From 7c1256f5f2056494d204be4090f0a977faa8e2d6 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 13 Mar 2022 17:30:24 +0100 Subject: [PATCH 1/4] Small improvement Now this will search Team Leaders if this is the first time or the Leader is missing. --- src/Ext/Script/Body.cpp | 58 ++++++++++++++++++++++++++++++++++++----- src/Ext/Team/Body.cpp | 1 + src/Ext/Team/Body.h | 2 ++ 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index 31456d198b..aee5602bdd 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -422,7 +422,17 @@ void ScriptExt::Mission_Gather_NearTheLeader(TeamClass *pTeam, int countdown = - double closeEnough; // Find the Leader - pLeaderUnit = FindTheTeamLeader(pTeam); + pLeaderUnit = pTeamData->TeamLeader; + if (!pLeaderUnit + || !pLeaderUnit->IsAlive + || pLeaderUnit->Health <= 0 + || pLeaderUnit->InLimbo + || !pLeaderUnit->IsOnMap + || pLeaderUnit->Absorbed) + { + pLeaderUnit = FindTheTeamLeader(pTeam); + pTeamData->TeamLeader = pLeaderUnit; + } if (!pLeaderUnit) { @@ -686,7 +696,17 @@ void ScriptExt::Mission_Attack(TeamClass *pTeam, bool repeatAction = true, int c } // Find the Leader - pLeaderUnit = FindTheTeamLeader(pTeam); + pLeaderUnit = pTeamData->TeamLeader; + if (!pLeaderUnit + || !pLeaderUnit->IsAlive + || pLeaderUnit->Health <= 0 + || pLeaderUnit->InLimbo + || !pLeaderUnit->IsOnMap + || pLeaderUnit->Absorbed) + { + pLeaderUnit = FindTheTeamLeader(pTeam); + pTeamData->TeamLeader = pLeaderUnit; + } if (!pLeaderUnit || bAircraftsWithoutAmmo || (pacifistTeam && !agentMode)) { @@ -2095,7 +2115,17 @@ void ScriptExt::Mission_Move(TeamClass *pTeam, int calcThreatMode = 0, bool pick } // Find the Leader - pLeaderUnit = FindTheTeamLeader(pTeam); + pLeaderUnit = pTeamData->TeamLeader; + if (!pLeaderUnit + || !pLeaderUnit->IsAlive + || pLeaderUnit->Health <= 0 + || pLeaderUnit->InLimbo + || !pLeaderUnit->IsOnMap + || pLeaderUnit->Absorbed) + { + pLeaderUnit = FindTheTeamLeader(pTeam); + pTeamData->TeamLeader = pLeaderUnit; + } if (!pLeaderUnit || bAircraftsWithoutAmmo) { @@ -2952,6 +2982,7 @@ FootClass* ScriptExt::FindTheTeamLeader(TeamClass* pTeam) { FootClass* pLeaderUnit = nullptr; int bestUnitLeadershipValue = -1; + bool teamLeaderFound = false; if (!pTeam) { @@ -2961,7 +2992,18 @@ FootClass* ScriptExt::FindTheTeamLeader(TeamClass* pTeam) // Find the Leader or promote a new one for (auto pUnit = pTeam->FirstUnit; pUnit; pUnit = pUnit->NextTeamMember) { - if (pUnit && pUnit->IsAlive + if (!pUnit) + continue; + + // Preventing >1 leaders in teams + if (teamLeaderFound) + { + pUnit->IsTeamLeader = false; + continue; + } + + if (pUnit->IsAlive + && pUnit->Health > 0 && !pUnit->InLimbo && pUnit->IsOnMap && !pUnit->Absorbed) @@ -2969,11 +3011,11 @@ FootClass* ScriptExt::FindTheTeamLeader(TeamClass* pTeam) if (pUnit->IsTeamLeader) { pLeaderUnit = pUnit; - break; + teamLeaderFound = true; + continue; } auto pUnitType = pUnit->GetTechnoType(); - if (pUnitType) { // The team Leader will be used for selecting targets, if there are living Team Members then always exists 1 Leader. @@ -2985,6 +3027,10 @@ FootClass* ScriptExt::FindTheTeamLeader(TeamClass* pTeam) } } } + else + { + pUnit->IsTeamLeader = false; + } } if (pLeaderUnit) diff --git a/src/Ext/Team/Body.cpp b/src/Ext/Team/Body.cpp index 07e8009030..54f359782c 100644 --- a/src/Ext/Team/Body.cpp +++ b/src/Ext/Team/Body.cpp @@ -18,6 +18,7 @@ void TeamExt::ExtData::Serialize(T& Stm) .Process(this->MoveMissionEndMode) .Process(this->WaitNoTargetCounter) .Process(this->WaitNoTargetTimer) + .Process(this->TeamLeader) ; } diff --git a/src/Ext/Team/Body.h b/src/Ext/Team/Body.h index 783a2b5110..a3ad86116f 100644 --- a/src/Ext/Team/Body.h +++ b/src/Ext/Team/Body.h @@ -23,6 +23,7 @@ class TeamExt int MoveMissionEndMode; int WaitNoTargetCounter; TimerStruct WaitNoTargetTimer; + FootClass* TeamLeader; ExtData(TeamClass* OwnerObject) : Extension(OwnerObject) , WaitNoTargetAttempts { 0 } @@ -33,6 +34,7 @@ class TeamExt , MoveMissionEndMode { 0 } , WaitNoTargetCounter { 0 } , WaitNoTargetTimer { 0 } + , TeamLeader { nullptr } { } virtual ~ExtData() = default; From 9c55669fd98f1ea1fe80cd769125f205742cb1a9 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 13 Mar 2022 17:49:38 +0100 Subject: [PATCH 2/4] small tweak --- src/Ext/Script/Body.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index 4b7322dc66..195b4106ce 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2778,7 +2778,7 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) if (percentage <= successPercentage) { - Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d = %d,%d) Next script line skipped successfuly. Next line will be: %d = %d,%d\n", + Debug::Log("DEBUG: [%s] [%s] (line: %d = %d,%d) Next script line skipped successfuly. Next line will be: %d = %d,%d\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->CurrentMission, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->CurrentMission].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->CurrentMission].Argument, pTeam->CurrentScript->CurrentMission + 2, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->CurrentMission + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->CurrentMission + 2].Argument); pTeam->CurrentScript->CurrentMission++; From 6ca28a43761a0c208b88fcc4231f343f7635a63b Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 13 Mar 2022 19:07:52 +0100 Subject: [PATCH 3/4] Point to latest YRpp --- YRpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YRpp b/YRpp index 0a4b65529a..7a71d0698b 160000 --- a/YRpp +++ b/YRpp @@ -1 +1 @@ -Subproject commit 0a4b65529a2d2501701f0ca97c3cdea62cd53090 +Subproject commit 7a71d0698b36e38761d93576127b2503909614b0 From 3ee2ddd2cfe21aa151e73fe77da5f20a03fe1e54 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Wed, 16 Mar 2022 16:10:50 +0100 Subject: [PATCH 4/4] Fix variable name --- src/Ext/Script/Body.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index 31cfb022fc..9d52c081dc 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -379,7 +379,7 @@ void ScriptExt::Mission_Gather_NearTheLeader(TeamClass *pTeam, int countdown = - double closeEnough; // Find the Leader - pLeaderUnit = pTeamData->TeamLeader; + pLeaderUnit = pExt->TeamLeader; if (!pLeaderUnit || !pLeaderUnit->IsAlive || pLeaderUnit->Health <= 0 @@ -388,7 +388,7 @@ void ScriptExt::Mission_Gather_NearTheLeader(TeamClass *pTeam, int countdown = - || pLeaderUnit->Absorbed) { pLeaderUnit = FindTheTeamLeader(pTeam); - pTeamData->TeamLeader = pLeaderUnit; + pExt->TeamLeader = pLeaderUnit; } if (!pLeaderUnit)