@@ -88,9 +88,9 @@ local function TryToJoinPlanet(planetData)
8888 return
8989 end
9090
91- lobby :PwJoinPlanet (planetData .PlanetID )
91+ lobby :PwJoinPlanet (planetData .PlanetID , planetData . AttackerFaction )
9292 if panelInterface then
93- panelInterface .SetPlanetJoined (planetData .PlanetID )
93+ panelInterface .SetPlanetJoined (planetData .PlanetID , planetData . AttackerFaction )
9494 end
9595 WG .Analytics .SendOnetimeEvent (" lobby:multiplayer:planetwars:join_site" )
9696end
@@ -199,6 +199,10 @@ local function ListToString(list)
199199 return outStr
200200end
201201
202+ local function HasAttackCharges ()
203+ return (WG .LibLobby .lobby :GetPlanetwarsData ().charges or 0 ) > 0
204+ end
205+
202206---- ----------------------------------------------------------------------------
203207---- ----------------------------------------------------------------------------
204208-- Timing
@@ -553,8 +557,9 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
553557 local planetAttacker = planetData .AttackerFaction
554558 local canSelectPlanet = planetData .CanSelectForBattle
555559 local myAttacking = planetData .PlayerIsAttacker
560+ local myDefending = planetData .PlayerIsDefender
556561
557- local joinedBattle = false
562+ local joinedBattle = myAttacking or myDefending
558563 local downloading = false
559564 local currentPlayers = planetData .Count or 0
560565 local maxPlayers = planetData .Needed or 0
@@ -655,6 +660,17 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
655660 text = " 0/0" ,
656661 parent = holder ,
657662 }
663+ local attackingCaption = TextBox :New {
664+ name = " attacking" ,
665+ x = 238 ,
666+ y = 55 ,
667+ width = 350 ,
668+ height = 20 ,
669+ valign = ' center' ,
670+ objectOverrideFont = Configuration :GetFont (3 ),
671+ text = " " ,
672+ parent = holder ,
673+ }
658674
659675 local function SetPlanetName (newPlanetName )
660676 newPlanetName = StringUtilities .GetTruncatedStringWithDotDot (newPlanetName , tbPlanetName .font , PLANET_NAME_LENGTH - 24 )
@@ -664,18 +680,25 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
664680 planetName = newPlanetName
665681 end
666682
667- local function UpdatePlayerCaption ()
668- if joinedBattle then
683+ local function UpdateCaptions ()
684+ if joinedBattle and not ( myAttacking and defendPhase ) then
669685 playerCaption :SetText (" Joined - Waiting for players: " .. currentPlayers .. " /" .. maxPlayers )
670686 else
671687 playerCaption :SetText (currentPlayers .. " /" .. maxPlayers )
672688 end
689+ if myAttacking and defendPhase then
690+ attackingCaption :SetText (" ** You are attacking **" )
691+ else
692+ attackingCaption :SetText (" " )
693+ end
673694 end
674695
675696 local function UpdateJoinButton ()
676- if not canSelectPlanet then
697+ local haveCharge = HasAttackCharges ()
698+ local needMap = not VFS .HasArchive (mapName )
699+ if not (canSelectPlanet and haveCharge ) or (canSelectPlanet and needMap ) then
677700 playerCaption :SetPos (104 )
678- UpdatePlayerCaption ()
701+ UpdateCaptions ()
679702 btnJoin :SetVisibility (false )
680703 btnLeave :SetVisibility (false )
681704 return
@@ -685,24 +708,23 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
685708 playerCaption :SetPos (104 )
686709 else
687710 playerCaption :SetPos (270 )
688- local haveMap = VFS .HasArchive (mapName )
689- if haveMap then
690- if attackPhase and canSelectPlanet then
691- btnJoin :SetCaption (i18n (" attack_planet" ))
692- elseif defendPhase and canSelectPlanet then
693- btnJoin :SetCaption (i18n (" defend_planet" ))
694- else
695- btnJoin :SetCaption (" ???" )
696- end
697- elseif canSelectPlanet then
711+ if needMap then
698712 if downloading then
699713 btnJoin :SetCaption (i18n (" downloading" ))
700714 else
701715 btnJoin :SetCaption (i18n (" download_map" ))
702716 end
717+ elseif canSelectPlanet and haveCharge then
718+ if attackPhase then
719+ btnJoin :SetCaption (i18n (" attack_planet" ))
720+ elseif defendPhase then
721+ btnJoin :SetCaption (i18n (" defend_planet" ))
722+ else
723+ btnJoin :SetCaption (" ???" )
724+ end
703725 end
704726 end
705- UpdatePlayerCaption ()
727+ UpdateCaptions ()
706728 btnJoin :SetVisibility (not joinedBattle )
707729 btnLeave :SetVisibility (joinedBattle )
708730 end
@@ -783,6 +805,8 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
783805 canSelectPlanet = newPlanetData .CanSelectForBattle
784806 attackPhase , defendPhase = newAttackPhase , newDefendPhase
785807 myAttacking = newPlanetData .PlayerIsAttacker
808+ myDefending = newPlanetData .PlayerIsDefender
809+ joinedBattle = myAttacking or myDefending
786810
787811 if planetID ~= newPlanetData .PlanetID then
788812 planetImage :Dispose ()
@@ -799,7 +823,7 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
799823 UpdateJoinButton ()
800824 end
801825
802- function externalFunctions .CheckDownload ()
826+ function externalFunctions .UpdateJoinCheck ()
803827 if not holder .visible then
804828 return
805829 end
@@ -830,8 +854,8 @@ local function MakePlanetControl(planetData, DeselectOtherFunc, attackPhase, def
830854 return {" a" .. planetName , planetName }
831855 end
832856
833- function externalFunctions .SetPlanetJoinedIfIDMatches (checkPlanetID )
834- if (not holder .visible ) or (planetID ~= checkPlanetID ) then
857+ function externalFunctions .SetPlanetJoinedIfIDMatches (checkPlanetID , checkPlanetAttacker )
858+ if (not holder .visible ) or (planetID ~= checkPlanetID ) or ( planetAttacker ~= checkPlanetAttacker ) then
835859 return
836860 end
837861
@@ -889,15 +913,15 @@ local function GetPlanetList(parentControl)
889913 end
890914 end
891915
892- function externalFunctions .CheckDownload ()
916+ function externalFunctions .UpdateJoinCheck ()
893917 for i = 1 , # planets do
894- planets [i ].CheckDownload ()
918+ planets [i ].UpdateJoinCheck ()
895919 end
896920 end
897921
898- function externalFunctions .SetPlanetJoined (planetID )
922+ function externalFunctions .SetPlanetJoined (planetID , planetAttacker )
899923 for i = 1 , # planets do
900- planets [i ].SetPlanetJoinedIfIDMatches (planetID )
924+ planets [i ].SetPlanetJoinedIfIDMatches (planetID , planetAttacker )
901925 end
902926 end
903927
@@ -1121,6 +1145,8 @@ local function InitializeControls(window)
11211145 local factionLinkButton
11221146
11231147 local oldAttackerFaction , oldDefenderFactions , oldMode = " " , {}, 1
1148+ local pwData = lobby :GetPlanetwarsData ()
1149+ local charges , rechargeTime = pwData .charges or 0 , pwData .nextRechargeTime
11241150
11251151 local lblTitle = Label :New {
11261152 x = 20 ,
@@ -1205,6 +1231,16 @@ local function InitializeControls(window)
12051231 parent = window
12061232 }
12071233
1234+ local chargesText = TextBox :New {
1235+ x = 20 ,
1236+ right = 16 ,
1237+ y = 120 ,
1238+ height = 50 ,
1239+ objectOverrideFont = Configuration :GetFont (2 ),
1240+ text = " " ,
1241+ parent = window
1242+ }
1243+
12081244 local function CheckPlanetwarsRequirements ()
12091245 local myUserInfo = lobby :GetMyInfo ()
12101246 if not (planetwarsSoon or planetwarsEnabled ) then
@@ -1261,36 +1297,54 @@ local function InitializeControls(window)
12611297 listHolder :SetVisibility (true )
12621298 return true
12631299 end
1264-
1265- local function UpdateStatusText (attackPhase , defending , currentMode )
1266- if not CheckPlanetwarsRequirements () then
1300+
1301+ local function UpdateChargesText (charges , rechargeTime )
1302+ if not CheckPlanetwarsRequirements () or missingResources then
1303+ return
1304+ end
1305+ if not (pwData .maxCharges and charges ) then
12671306 return
12681307 end
1308+ local text = " Attack charges: " .. charges .. " / " .. pwData .maxCharges
1309+ if rechargeTime then
1310+ local difference , inTheFuture , isNow = Spring .Utilities .GetTimeDifference (rechargeTime , false , true )
1311+ if inTheFuture then
1312+ text = text .. " - Passive recharge in " .. difference
1313+ else
1314+ text = text .. " - Passive recharge in 0 seconds"
1315+ end
1316+ end
1317+ text = text .. " \n Spend charges to attack and regain them by defending planets."
1318+ chargesText :SetText (text )
1319+ end
12691320
1270- if missingResources then
1321+ local function UpdateStatusText (attackPhase , defending , currentMode )
1322+ if not CheckPlanetwarsRequirements () or missingResources then
12711323 return
12721324 end
12731325
12741326 if attackPhase then
1275- if currentMode == lobby .PW_ATTACK then
1327+ if charges == 0 then
1328+ statusText :SetText (" You are out of attack charges. You need to defend a planet or wait for passive recharge." )
1329+ elseif currentMode == lobby .PW_ATTACK then
12761330 statusText :SetText (" Choose a planet to attack. All attacks that reach the player threshold are launched when the timer reaches zero." )
12771331 else
12781332 local planets = lobby .planetwarsData .planets
12791333 local noPlanets = not (planets and planets [1 ])
12801334 local planetName = planets and (FindMyattackPhasePlanet (planets ) or (planets [1 ] and not planets [2 ] and planets [1 ].PlanetName ))
12811335 if lobby .planetwarsData .attackPhasePlanet then
12821336 if planetName then
1283- statusText :SetText (" You are attackPhase " .. planetName .. " . The defenders have limited time to respond." )
1337+ statusText :SetText (" You are attacking " .. planetName .. " . The defenders have limited time to respond." )
12841338 else
1285- statusText :SetText (" You attackPhase a planet. Wait for the defenders have limited time to respond." )
1339+ statusText :SetText (" You are attacking a planet. Wait for the defenders have limited time to respond." )
12861340 end
12871341 elseif noPlanets then
12881342 statusText :SetText (" Your faction has launched an attack. The defenders have limited time to respond" )
12891343
12901344 elseif planetName then
1291- statusText :SetText (" Your faction is attackPhase " .. planetName .. " . The defenders have limited time to respond" )
1345+ statusText :SetText (" Your faction is attacking " .. planetName .. " . The defenders have limited time to respond" )
12921346 else
1293- statusText :SetText (" Your faction is attackPhase multiple planets. The defenders have limited time to respond" )
1347+ statusText :SetText (" Your faction is attacking multiple planets. The defenders have limited time to respond" )
12941348 end
12951349 end
12961350 else
@@ -1333,6 +1387,7 @@ local function InitializeControls(window)
13331387 end
13341388
13351389 local attackPhase , defendPhase = GetattackPhaseOrDefending (lobby , attackerFactions , defenderFactions , currentMode )
1390+ UpdateChargesText (charges , rechargeTime )
13361391 UpdateStatusText (attackPhase , defendPhase , currentMode )
13371392
13381393 planetList .SetPlanetList (planets , attackPhase , defendPhase , modeSwitched )
@@ -1342,22 +1397,31 @@ local function InitializeControls(window)
13421397
13431398 local function OnPwattackPhasePlanet ()
13441399 local attackPhase , defendPhase = GetattackPhaseOrDefending (lobby , oldAttackerFaction , oldDefenderFactions , oldMode )
1400+ UpdateChargesText (charges , rechargeTime )
13451401 UpdateStatusText (attackPhase , defendPhase , oldMode )
13461402 end
13471403 lobby :AddListener (" OnPwattackPhasePlanet" , OnPwattackPhasePlanet )
13481404
13491405 local function OnUpdateUserStatus (listener , userName , status )
13501406 if lobby :GetMyUserName () == userName then
13511407 local attackPhase , defendPhase = GetattackPhaseOrDefending (lobby , oldAttackerFaction , oldDefenderFactions , oldMode )
1408+ UpdateChargesText (charges , rechargeTime )
13521409 UpdateStatusText (attackPhase , defendPhase , oldMode )
13531410 end
13541411 end
13551412 lobby :AddListener (" OnUpdateUserStatus" , OnUpdateUserStatus )
13561413
1414+ local function OnPwAttackCharges (listener , newCharges , newRechargeTime )
1415+ charges , rechargeTime = newCharges , newRechargeTime
1416+ UpdateChargesText (charges , rechargeTime )
1417+ UpdateStatusText (attackPhase , defendPhase , oldMode )
1418+ planetList .UpdateJoinCheck ()
1419+ end
1420+ lobby :AddListener (" OnPwAttackCharges" , OnPwAttackCharges )
13571421 local externalFunctions = {}
13581422
13591423 function externalFunctions .CheckDownloads ()
1360- planetList .CheckDownload ()
1424+ planetList .UpdateJoinCheck ()
13611425 if not HaveRightEngineVersion () then
13621426 if CheckPlanetwarsRequirements () then
13631427 statusText :SetText (MISSING_ENGINE_TEXT )
@@ -1548,11 +1612,11 @@ function DelayedInitialize()
15481612
15491613 DoUnMatchedActivityUpdate = UnMatchedActivityUpdate
15501614
1551- local function OnPwRequestJoinPlanet (listener , joinPlanetID )
1615+ local function OnPwRequestJoinPlanet (listener , joinPlanetID , planetAttacker )
15521616 local planetwarsData = lobby :GetPlanetwarsData ()
15531617 local planets = planetwarsData .planets
15541618 for i = 1 , # planets do
1555- if joinPlanetID == planets [i ].PlanetID then
1619+ if joinPlanetID == planets [i ].PlanetID and planetAttacker == planets [ i ]. AttackerFaction then
15561620 TryToJoinPlanet (planets [i ])
15571621 break
15581622 end
0 commit comments