Skip to content

Commit dc2719d

Browse files
committed
More RK logic.
1 parent eac85ac commit dc2719d

5 files changed

Lines changed: 159 additions & 32 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
local rewardDefs = VFS.Include("LuaRules/Configs/RogueK/reward_defs.lua")
3+
4+
local loadout = {
5+
rerolls = 3,
6+
factories = {
7+
{
8+
baseDef = "factoryjump",
9+
units = {},
10+
},
11+
{
12+
baseDef = "factorytank",
13+
units = {},
14+
},
15+
{
16+
baseDef = "factoryplane",
17+
units = {},
18+
},
19+
},
20+
commander = {
21+
},
22+
structures = {
23+
"staticmex",
24+
"energywind",
25+
"energysolar",
26+
"staticrearm",
27+
"staticradar",
28+
},
29+
}
30+
31+
local function TranslateStringList(data)
32+
for i = 1, #data do
33+
if type(data[i]) == "string" then
34+
data[i] = rewardDefs.flatRewards[data[i]]
35+
end
36+
end
37+
end
38+
39+
TranslateStringList(loadout.structures)
40+
TranslateStringList(loadout.commander)
41+
for i = 1, #loadout.factories do
42+
TranslateStringList(loadout.factories[i])
43+
end
44+
45+
46+
return loadout

LuaRules/Configs/RogueK/reward_defs.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ local function MakeUnitUnlock(name)
1313
local def = {
1414
name = name,
1515
humanName = ud.humanName,
16+
description = (ud.humanName or "???") .. " - " .. (Spring.Utilities.GetDescription(ud) or ""),
17+
image = 'unitpics/' .. name .. '.png',
1618
unitDefName = name,
1719
structure = not moveType,
1820
factory = moveType and ((moveType == 2 and 1) or 3),
@@ -21,6 +23,33 @@ local function MakeUnitUnlock(name)
2123
return def
2224
end
2325

26+
local commChassiOptions = {
27+
{
28+
name = "commstrike",
29+
humanName = "Strike Chassis",
30+
image = 'unitpics/commstrike.png',
31+
commander = true,
32+
},
33+
{
34+
name = "commsupport",
35+
humanName = "Engineer Chassis",
36+
image = 'unitpics/commsupport.png',
37+
commander = true,
38+
},
39+
{
40+
name = "commrecon",
41+
humanName = "Recon Chassis",
42+
image = 'unitpics/commrecon.png',
43+
commander = true,
44+
},
45+
{
46+
name = "commassault",
47+
humanName = "Guardian Chassis",
48+
image = 'unitpics/commassault.png',
49+
commander = true,
50+
},
51+
}
52+
2453
local function ProcessUnitList(unitList)
2554
local out = {}
2655
for i = 1, #unitList do
@@ -30,6 +59,11 @@ local function ProcessUnitList(unitList)
3059
end
3160

3261
local categories = {
62+
comm_chassis = {
63+
humanName = "Commander",
64+
base_options = 4,
65+
options = commChassiOptions,
66+
},
3367
constructor = {
3468
humanName = "Constructor",
3569
options = ProcessUnitList({
@@ -68,11 +102,26 @@ local categories = {
68102
"turretemp",
69103
}),
70104
},
105+
start_structures = {
106+
humanName = "Starting Structures",
107+
options = ProcessUnitList({
108+
"staticmex",
109+
"energywind",
110+
"energysolar",
111+
"staticradar",
112+
}),
113+
},
71114
}
72115

116+
-- How many options are shown for a reward and how many extra are added with tech points.
117+
local BASE_OPTIONS = 3
118+
local TECH_OPTIONS = 3
119+
73120
local flatRewards = {}
74121
local alreadyIn = {}
75122
for reward, data in pairs(categories) do
123+
data.base_options = data.base_options or BASE_OPTIONS
124+
data.extra_options = data.extra_options or TECH_OPTIONS
76125
for i = 1, #data.options do
77126
local name = data.options[i].name
78127
if not alreadyIn[name] then

LuaRules/Gadgets/game_rogue_progression.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ local CustomKeyToUsefulTable = Spring.Utilities.CustomKeyToUsefulTable
2626

2727
local PLAYER_ALLYTEAM = 0
2828

29-
-- How many options are shown for a reward and how many extra are added with tech points.
30-
local BASE_OPTIONS = 3
31-
local TECH_OPTIONS = 3
3229

3330
local extraRewards = {} -- TODO, mid-mission bonus objective rewards are registered here
3431

@@ -38,13 +35,13 @@ local function SetupTeamProgression(teamID, rewards)
3835
-- The host reads rk_loadout when creating the next game. Players send updated
3936
-- loadouts to luarules for this purpose.
4037
Spring.SetTeamRulesParam(teamID, "rk_loadout", customKeys.rk_loadout)
38+
Spring.Echo("Writing loading for", teamID)
4139

4240
for i = 1, #rewards do
4341
local reward = rewardDefs.categories[rewards[i]]
44-
Spring.Echo("humanNamehumanNamehumanName", reward.humanName)
4542
Spring.SetTeamRulesParam(teamID, "rk_reward_name_" .. i, rewards[i])
46-
Spring.SetTeamRulesParam(teamID, "rk_reward_display_count_" .. i, BASE_OPTIONS)
47-
Spring.SetTeamRulesParam(teamID, "rk_reward_display_tech_" .. i, TECH_OPTIONS)
43+
Spring.SetTeamRulesParam(teamID, "rk_reward_display_count_" .. i, reward.base_options)
44+
Spring.SetTeamRulesParam(teamID, "rk_reward_display_extra_per_tech_" .. i, reward.extra_options)
4845
Spring.Utilities.PermuteList(reward.options)
4946
for j = 1, #reward.options do
5047
Spring.SetTeamRulesParam(teamID, "rk_reward_option_" .. i .. "_" .. j, reward.options[j].name)

LuaRules/Utilities/unitDefReplacements.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function Spring.Utilities.GetDescription(ud, unitID)
269269
end
270270

271271
local name_override = ud.customParams.statsname or ud.name
272-
local desc = WG.Translate ("units", name_override .. ".description") or ud.tooltip
272+
local desc = (WG and WG.Translate ("units", name_override .. ".description")) or ud.tooltip
273273
local isValidUnit = Spring.ValidUnitID(unitID)
274274
if isValidUnit then
275275
local customTooltip = GetCustomTooltip(unitID, ud)
@@ -280,7 +280,7 @@ function Spring.Utilities.GetDescription(ud, unitID)
280280

281281
local buildSpeed = spGetUnitBuildSpeed(unitID, ud.id)
282282
if buildSpeed > 0 then
283-
return WG.Translate("interface", "builds_at", {desc = desc, bp = math.round(buildSpeed, 1)}) or desc
283+
return (WG and WG.Translate("interface", "builds_at", {desc = desc, bp = math.round(buildSpeed, 1)})) or desc
284284
end
285285
return desc
286286
end
@@ -389,7 +389,7 @@ if Spring.GetModOptions().techk == "1" and WG then
389389
end
390390

391391
local name_override = ud.customParams.statsname or ud.name
392-
local desc = WG.Translate ("units", name_override .. ".description") or ud.tooltip
392+
local desc = (WG and WG.Translate ("units", name_override .. ".description")) or ud.tooltip
393393
local isValidUnit = Spring.ValidUnitID(unitID)
394394
if isValidUnit then
395395
local tech = GetTechLevel(unitID) or 1
@@ -405,7 +405,7 @@ if Spring.GetModOptions().techk == "1" and WG then
405405
local mult = math.pow(2, (WG.SelectedTechLevel or 1) - 1)
406406
buildSpeed = buildSpeed * mult
407407
end
408-
return WG.Translate("interface", "builds_at", {desc = desc, bp = math.round(buildSpeed, 1)}) or desc
408+
return (WG and WG.Translate("interface", "builds_at", {desc = desc, bp = math.round(buildSpeed, 1)})) or desc
409409
end
410410
return desc
411411
end

LuaUI/Widgets/gui_chili_rogue_rewards.lua

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ local loadoutDisplay
5454

5555
--------------------------------------------------------------------------------
5656
--------------------------------------------------------------------------------
57-
-- Utils
57+
-- Loadout Handling
5858

5959
local function AddItemToLoadout(reward)
6060
local targetTable
@@ -66,6 +66,9 @@ local function AddItemToLoadout(reward)
6666
elseif reward.structure then
6767
targetTable = currentLoadout.structures
6868
itemType = "structure"
69+
elseif reward.commander then
70+
targetTable = currentLoadout.commander
71+
itemType = "commander"
6972
end
7073
targetTable[#targetTable + 1] = reward
7174
loadoutDisplay.AddToLoadoutDisplay(reward)
@@ -76,6 +79,21 @@ local function SendLoadout()
7679
Spring.SendLuaRulesMsg("rk_loadout " .. encoded)
7780
end
7881

82+
local function ReadLoadout()
83+
local teamID = Spring.GetMyTeamID()
84+
local encoded = Spring.GetTeamRulesParam(teamID, "rk_loadout")
85+
local loadout = CustomKeyToUsefulTable(encoded)
86+
if loadout.needInit then
87+
loadout = VFS.Include("LuaRules/Configs/RogueK/base_loadout.lua")
88+
end
89+
return loadout
90+
end
91+
92+
--------------------------------------------------------------------------------
93+
--------------------------------------------------------------------------------
94+
-- Utils
95+
96+
7997
local function ClickRewardCategoryButton(buttonID)
8098
for i = 1, #rewardButtons do
8199
rewardButtons[i].SetSelection(buttonID == i)
@@ -155,9 +173,6 @@ local function SetupRewardSelectionView(parent)
155173
holder:SetVisibility(true)
156174

157175
for i = 1, math.max(#buttons, #rewardOptions) do
158-
if not rewardOptions[i] then
159-
buttons[i]:SetVisibility(false)
160-
end
161176
if not buttons[i] then
162177
buttons[i] = Chili.Button:New{
163178
parent = holder,
@@ -168,10 +183,15 @@ local function SetupRewardSelectionView(parent)
168183
height = 45,
169184
}
170185
end
171-
local rewardName = rewardOptions[i]
172-
buttons[i]:SetCaption(rewardDefs.flatRewards[rewardName].humanName)
173-
buttons[i].OnClick[1] = function ()
174-
SelectReward(buttonID, rewardID, rewardName)
186+
if rewardOptions[i] then
187+
local rewardName = rewardOptions[i]
188+
buttons[i]:SetCaption(rewardDefs.flatRewards[rewardName].humanName)
189+
buttons[i].OnClick[1] = function ()
190+
SelectReward(buttonID, rewardID, rewardName)
191+
end
192+
buttons[i]:SetVisibility(true)
193+
else
194+
buttons[i]:SetVisibility(false)
175195
end
176196
end
177197
end
@@ -349,24 +369,35 @@ local function MakeRewardList(holder, name, leftBound, rightBound, itemList)
349369

350370
function externalFunctions.AddItem(item)
351371
x, y, paragraphOffset = GetIconPosition(posIndex, iconsAcross, paragraphOffset)
352-
local rawTooltip = item.name
353-
local imageControl = Chili.Image:New{
372+
local button = Chili.Button:New{
354373
x = x,
355374
y = y,
356375
width = LOADOUT_ICON_SIZE,
357376
height = LOADOUT_ICON_SIZE,
358-
keepAspect = true,
359-
color = color,
360-
tooltip = item.name,
361-
file = 'unitpics/' .. item.name .. '.png',
377+
tooltip = item.description,
378+
caption = false,
379+
padding = {0, 0, 0, 0},
380+
noFont = true,
362381
parent = rewardsHolder,
363382
}
383+
local image = Chili.Image:New{
384+
x = 0,
385+
y = 0,
386+
width = LOADOUT_ICON_SIZE,
387+
height = LOADOUT_ICON_SIZE,
388+
file = item.image,
389+
parent = button,
390+
}
364391
local text = Chili.TextBox:New{
365392
text = item.humanName or item.name,
366-
parent = imageControl,
393+
x = 4,
394+
y = 4,
395+
right = 4,
396+
font = {size = 10},
397+
parent = image,
367398
}
368399
itemControls[#itemControls + 1] = {
369-
image = imageControl,
400+
button = button,
370401
}
371402
posIndex = posIndex + 1
372403
end
@@ -381,7 +412,7 @@ local function MakeRewardList(holder, name, leftBound, rightBound, itemList)
381412
posIndex = 0
382413
for i = 1, #itemControls do
383414
x, y, paragraphOffset = GetIconPosition(posIndex, iconsAcross, paragraphOffset)
384-
itemControls[i].image:SetPos(x, y)
415+
itemControls[i].button:SetPos(x, y)
385416

386417
posIndex = posIndex + 1
387418
end
@@ -402,14 +433,18 @@ local function SetupLoadoutPanel(bottomPanel)
402433
return
403434
end
404435

405-
local structures
436+
local structures, commanderModules
406437
local factories = {}
407438
local function ResizeLoadout(xSize)
408439
local offset = 5
409440
if structures then
410441
structures.ResizeFunction(xSize / 2)
411442
offset = structures.SetPosition(offset)
412443
end
444+
if commanderModules then
445+
commanderModules.ResizeFunction(xSize / 2)
446+
offset = commanderModules.SetPosition(offset)
447+
end
413448

414449
offset = 5
415450
for i = 1, #factories do
@@ -439,6 +474,7 @@ local function SetupLoadoutPanel(bottomPanel)
439474
}
440475

441476
structures = MakeRewardList(loadoutPanel, "Structures", "50%", 12, currentLoadout.structures)
477+
commanderModules = MakeRewardList(loadoutPanel, "Commander", "50%", 12, currentLoadout.commander)
442478
for i = 1, #currentLoadout.factories do
443479
factories[i] = MakeRewardList(loadoutPanel, "Factory " .. i, 12, "50%", currentLoadout.factories[i].units)
444480
end
@@ -451,6 +487,8 @@ local function SetupLoadoutPanel(bottomPanel)
451487
factories[item.factory].AddItem(item)
452488
elseif item.structure then
453489
structures.AddItem(item)
490+
elseif item.commander then
491+
commanderModules.AddItem(item)
454492
end
455493
ResizeLoadout(loadoutPanel.width)
456494
end
@@ -542,10 +580,7 @@ local function MakePostgamePanel()
542580
end
543581

544582
local function InitializeRewardSelection()
545-
local teamID = Spring.GetMyTeamID()
546-
local encoded = Spring.GetTeamRulesParam(teamID, "rk_loadout")
547-
currentLoadout = CustomKeyToUsefulTable(encoded)
548-
583+
currentLoadout = ReadLoadout()
549584
MakePostgamePanel()
550585
ClickFirstEnabledButton()
551586
end

0 commit comments

Comments
 (0)