FreeSpace Releases > Scripting Releases

[Alpha Release] Ability Management Framework

<< < (2/6) > >>

X3N0-Life-Form:
Alright, I've had some more time to think about all this and started implementing the basics (emphasis on started).

I'm still not sure how to handle always on or global abilities and a few other details, but I've got a clearer idea of what I want to do.

On the technical side, I seem to have gotten over my multi-dimensional array madness and started using proper data structures, so that's a plus (although it does make me want to go back to my parsing script and fix the giant table blob -_-).

It's going slowly, but I'm hoping to have some sort of basic working prototype by the end of July.


Anyway, here is the table prototype:

--- Code: ---#Abilities

; $Name: string
; $Target Type:   list of string (self, fighter, corvette, tagged, buff:buffType)
; $Target Team: list of string (hostile, friendly, neutral, relative to the caster)
; $Range: integer (optional)
;   +Min: integer (minimum range) (optional)
; $Cost: integer/list of integer (tied to diffculty level) (optional)
;   +Cost type: string (weapon energy reserve, "ammo" specific to that ability, "mana" reserve shared by all abilities) (optional)
; $Buff: list of string (optional)
; $Duration: list of int (optional)
; $Ability Data: metadata used by whatever script actually uses the ability

$Name:          SSM-moloch
$Target Type:   big ship
$Target Team:   Hostile
$Cost:          1
  +Cost Type:   global-ammo:SSM-moloch-ammo/ammo
;; how about having multiple cost types ?
$Ability Data:
  +Strike Type: Shivan SSM Strike

$Name:          Shivan Command aura ;; TODO: ai buff ?
$Target Type:   fighter, bomber
$Target Team:   Friendly
$Range:         4000
$Buff:          command aura
$Ability Data:
  +Max AI:      Colonel

$Name:          Energy Dampening Field ;; TODO : energy drain thingy
$Target Type:   fighter, bomber
$Target Team:   Hostile
$Range:         1500
$Cost:          70
  +Cost Type:   energy:weapon
$Cooldown:      90
$Duration:      15


#End

--- End code ---

The script itself so far:

--- Code: ---
------------------------
--- Global Variables ---
------------------------

ability_classes = {}
ability_instances = {}


-- set to true to enable prints
ability_enableDebugPrints = true

----------------------
--- ??? Functions ---
----------------------


function ability_fireAllPossible()
-- TODO : cycle through ability instances & fire them
end

-------------------------
--- Utility Functions ---
-------------------------

function dPrint_ability(message)
if (ability_enableDebugPrints) then
ba.print("[abilityManager.lua] "..message)
end
end

--[[
Return the specified class as a string.

@param className : name of the class
]]
function ability_getClassAsString(className)
--TODO
end

----------------------
--- Core Functions ---
----------------------


function ability_createClass(name, attributes)
-- Initialize the class
ability_classes[name] = {
  Name = name,
  TargetType = attributes['Target Type']['value'],
  TargetTeam = attributes['Target Team']['value'],
  Cooldown = nil,
  Duration = nil,
  Range = -1,
  Cost = 0,
  CostType = nil
}

if not (attributes['Cooldown'] == nil) then
ability_classes[name].Cooldown = attributes['Cooldown']['value']
end

if not (attributes['Range'] == nil) then
ability_classes[name].Range = attributes['Range']['value']
end

if not (attributes['Cost'] == nil) then
ability_classes[name].Cost = attributes['Cost']['value']
if not (attributes['Cost']['sub'] == nil) then --TODO : utility function to grab a sub attributes' value ???
if not (attributes['Cost']['sub']['Cost Type'] == nil) then
ability_classes[name].CostType = attributes['Cost']['sub']['Cost Type']
end
end
end

if not (attributes['Duration'] == nil) then
ability_classes[name].Duration = attributes['Duration']['value']
end

-- Print class
dPrint_ability(ability_getClassAsString(name))
end

--[[
Reset the instance array. Should be called $On Gameplay Start.
]]
function ability_resetInstances()
ability_instances = {}
end


--[[
Create an instance of the specified ability and tie it to the specified shipName.

@param instanceId : unique identifier for this instance
@param className : name of the ability
@param shipName : ship to tie the ability to. Can be nil.
]]
function ability_createInstance(instanceId, className, shipName)
ability_instances[instanceId] = {
Class = className,
Ship = shipName,
LastFired = 0,
Active = true,
Manual = false, --if that instance must be fire manually
Ammo = -1 --needs to be set after creation if necessarys
}
end

--[[
Verify that this ability instance can be fired

@param instanceId : id of the ability instance to test
@return true if it can
]]
function ability_canBeFired(instanceId)
-- Check that this is a valid idea
if (ability_instances[instanceId] == nil) then
ba.warning("[abilityManager.lua] Unknown instance id : "..instanceId)
return false
end

local instance = ability_instances[instanceId]
local class = ability_classes[instance.Class]
-- Verify that this instance is active
if (instance.Active) then
-- Verify cooldown
local missionTime = mn.getMissionTime()
local cooldown = class.Cooldown
if (instance.LastFired + cooldown >= missionTime) then
--TODO : Verify cost
return true
end
end

-- Default
return false
end

------------
--- main ---
------------

abilityTable = parseTableFile("data/config/", "abilities.tbl")

ba.print(getTableObjectAsString(abilityTable))


for name, attributes in pairs(abilityTable['Abilities']) do
ability_createClass(name, attributes)
end

--- End code ---

Axem:
The only thing that leaps out at me right now is...

abilityTable = parseTableFile("data/config/", "abilities.tbl")

Beware, while it may work for you in testing, FreeSpace will not look for a tbl file in /config/ in a VP file. FS will only look at cfg files in config, and tbl/tbm in tables. (Atleast if I'm correct in guessing that first argument is what directory to look in?)

AdmiralRalwood:

--- Quote from: X3N0-Life-Form on June 29, 2016, 02:59:38 pm ---
--- Code: ---$Name:          Energy Dampening Field ;; TODO : energy drain thingy
$Target Type:   fighter, bomber
$Target Team:   Hostile
$Range:         1500
$Cost:          70
  +Cost Type:   energy:weapon
$Cooldown:      90
$Duration:      15

--- End code ---

--- End quote ---
Wouldn't the cost be paid by the caster, not the targets? It would be rather odd if an energy dampening field drained its bearer's weapon energy for every hostile strikecraft in range...

X3N0-Life-Form:
Well obviously firing the thing is supposed to have a cost. I'm still far away from having the abilities actually do anything, so I haven't put anything related to the "Energy Dampening Field"'s actual effects.

Basically, the script is meant to determine when an ability can be fired, then call the actual function meant to apply the effects, and finally do a bit of book keeping like draining the caster's energy reserve/ammo/whatever.

EDIT - Stuff related to ability's effects would go under $Ability Data:


--- Quote from: Axem on June 29, 2016, 08:26:59 pm ---The only thing that leaps out at me right now is...

abilityTable = parseTableFile("data/config/", "abilities.tbl")

Beware, while it may work for you in testing, FreeSpace will not look for a tbl file in /config/ in a VP file. FS will only look at cfg files in config, and tbl/tbm in tables. (Atleast if I'm correct in guessing that first argument is what directory to look in?)

--- End quote ---

Huh, I wasn't aware of that. Well I guess that it's something else I need to put on my TODO list ...

X3N0-Life-Form:
Hello folks, it's time to post a small update.

The thing's really starting to take shape :
- The core data structures are close to final, along with all sorts of utility functions to help debug things as I go along.
- This also allowed me to stress test my old parsing script a bit and fix a couple of bugs, the most notable one being sub-attributes not being parsed. I've also added a couple of utility functions + improved the debugging messages in there as well. (Which means that it might be a good idea to post a new release of the parsing script as soon as things stabilize a bit.)
- Data parsing is basically done (see updated table below).
- Ability instanciation is working
- Preliminary tests indicate that the canBeFired function seems to be working


So, the next big steps are:
- Target handling
- Write a basic fire function
- Write a function that loops through all active instances and fires the abilities that can be fired
- Complete cost type handling
- Store ability data properly
- Write a basic ability function to test all of the above


The next big milestone's gonna be target handling, the rest should be fairly trivial in comparison.


Updated table:

--- Code: ---#Abilities

; $Name: string
; $Target Type:   list of string (self, fighter, corvette, tagged, buff:buffType)
; $Target Team: list of string (hostile, friendly, neutral, relative to the caster)
; $Range: integer (optional)
;   +Min: integer (minimum range) (optional)
; $Cost: integer/list of integer (tied to diffculty level) (optional)
;   +Cost type: string (weapon energy reserve, what ammo consumption system is to be used) (optional)
; $Buff: list of string (optional)
; $Cooldown:      90
; $Duration: list of int (optional)
; $Ability Data: metadata used by whatever script actually uses the ability

$Name: SSM-moloch-std
$Target Type:   big ship
$Target Team:   Hostile
$Cooldown: 24, 20, 17, 15, 13
$Ability Data:
  +Strike Type: Shivan SSM Strike

$Name:          SSM-moloch-std-global ;; concept : global ammo
$Target Type:   big ship
$Target Team:   Hostile
$Cost:          1
  +Cost Type:   global:SSM-moloch-ammo
  +Starting Reserve: 15;;TODO : handle + add to the spec above
$Cooldown: 24, 20, 17, 15, 13
$Ability Data:
  +Strike Type: Shivan SSM Strike

$Name:          Shivan Command aura ;; concept : passive ability
$Target Type:   fighter, bomber
$Target Team:   Friendly
$Range:         4000
$Buff:          command aura
$Ability Data:
  +Max AI:      Colonel

$Name:          Energy Dampening Field ;; concept : energy cost type
$Target Type:   fighter, bomber
$Target Team:   Hostile
$Range:         1500
$Cost:          70
  +Cost Type:   energy:weapon
$Cooldown:      90
$Duration:      15


#End

--- End code ---

Latest version of the script is here.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version