Skip to content

Commit

Permalink
template: allow some assets to regenerate
Browse files Browse the repository at this point in the history
Define a new template attribute `regenerate` that when `true` will cause the
given asset to lookup the template it was based off of and copy over the
`tpldata` again.

Currently only StaticAssets comply with this setting as no other assets
utilize tpldata in any meaningful way.

Closes: #117
  • Loading branch information
jtoppins committed Jan 26, 2021
1 parent 9354deb commit 9250e29
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
metadata = {
["rank"] = 2,
["objtype"] = "basedefense",

["base"] = "Bandar-e-jask airfield",
["regenerate"] = true,
}
9 changes: 9 additions & 0 deletions doc/03-designer.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,15 @@ ignored by the DCT AI. This includes scheduling the asset to be assigned
as a target to a player. [TODO] This will also make any units spawned
by the asset to be ignored by the DCS AI.

### `regenerate`

* _required:_ no
* _value:_ boolean
* _default:_ false

Forces an asset on state reload to reset its `tpldata` to the original
state when the asset was created.

### Attributes - Type Specific

#### Airspace
Expand Down
2 changes: 2 additions & 0 deletions src/dct/assets/AssetBase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function AssetBase:__init(template, region)
"codename",
"cost",
"ignore",
"regenerate",
})
self._spawned = false
self._dead = false
Expand Down Expand Up @@ -154,6 +155,7 @@ function AssetBase:_completeinit(template, region)
print(string.format("Template(%s) has nil 'desc' field",
template.name))
end
self.regenerate = template.regenerate
self.ignore = template.ignore
self.owner = template.coalition
self.rgnname = region.name
Expand Down
6 changes: 5 additions & 1 deletion src/dct/assets/StaticAsset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ function StaticAsset:marshal()
if tbl == nil then
return nil
end
tbl._tpldata = filterTemplateData(self._tpldata)
if self.regenerate then
tbl._tpldata = self._tpldata
else
tbl._tpldata = filterTemplateData(self._tpldata)
end
if tbl._tpldata == nil then
return nil
end
Expand Down
4 changes: 4 additions & 0 deletions src/dct/templates/Template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ local function getkeys(objtype)
["name"] = "ignore",
["type"] = "boolean",
["default"] = false,
}, {
["name"] = "regenerate",
["type"] = "boolean",
["default"] = false,
}, {
["name"] = "priority",
["type"] = "number",
Expand Down

0 comments on commit 9250e29

Please sign in to comment.