Skip to content

Commit

Permalink
tickets: allow campaign config to be changed mid campaign
Browse files Browse the repository at this point in the history
Before this change the whole ticket configuration would be saved to the
state file. This made modifying the ticket configuration impossible mid
campaign which makes campaign balancing an issue. With this change only
the current ticket count and the original ticket start values are saved
to the state file. All modifiers and difficulty can be modified by
stopping the server, modifying the difficulty, and reloading the start
file.
  • Loading branch information
jtoppins committed Mar 20, 2023
1 parent 4878443 commit e7cde2f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/dct/systems/tickets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local Command = require("dct.libs.Command")
local Check = require("dct.templates.checkers.Check")
local UPDATE_TIME = 120

local coa_list = {"red", "blue", "neutral"}

local difficulty = {
["EASY"] = {
["player_cost"] = 1.0,
Expand Down Expand Up @@ -168,7 +170,7 @@ function CheckGoals:check(data)

local checkside = CheckSide()

for _, side in pairs({"red", "blue", "neutral"}) do
for _, side in pairs(coa_list) do
ok, key, msg = checkside:check(data[side])

if not ok then
Expand Down Expand Up @@ -200,12 +202,9 @@ function Tickets:__init(theater)
end
end

function Tickets:_unmarshalpost(data)
for _, tbl in ipairs({"tickets"}) do
self[tbl] = {}
for k, v in pairs(data[tbl]) do
self[tbl][tonumber(k)] = v
end
function Tickets:unmarshal(data)
for k, v in pairs(data.tickets) do
utils.mergetables(self.tickets[tonumber(k)], v)
end

if self.timeout then
Expand All @@ -214,9 +213,22 @@ function Tickets:_unmarshalpost(data)
end
end

local include_list = {
["start"] = true,
["tickets"] = true,
}

function Tickets:marshal()
local data = Marshallable.marshal(self)

for _, coa in pairs(coalition.side) do
for key, _ in pairs(data.tickets[coa]) do
if include_list[key] == nil then
data.tickets[coa][key] = nil
end
end
end

if self.timeout then
data.timeleft = self.timer:remain()
end
Expand All @@ -238,7 +250,7 @@ function Tickets:readconfig()
self.timer = Timer(goals.time, timer.getAbsTime)
self.timeout = true
end
for _, val in ipairs({"red", "blue", "neutral"}) do
for _, val in ipairs(coa_list) do
local s = coalition.side[string.upper(val)]
self.tickets[s] = goals[val]
self.tickets[s].name = val
Expand Down

0 comments on commit e7cde2f

Please sign in to comment.