From 02aa9e607b9c31a16af36f3cec4c2b45c3b91d42 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Thu, 28 Oct 2021 16:20:47 +0200 Subject: [PATCH 01/12] Initial commit In this Action 113, the argument is a percentage value from (integer from 0 to 100) and is the success rate for skipping the next script action (instead of jumping to the line n+1 it would jump to n+2). --- src/Ext/Script/Body.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/Ext/Script/Body.h | 1 + 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index df778abcb8..227e91267e 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -141,6 +141,9 @@ void ScriptExt::ProcessAction(TeamClass* pTeam) case 112: ScriptExt::Mission_Gather_NearTheLeader(pTeam, -1); break; + case 113: + ScriptExt::SkipNextAction(pTeam, -1); + break; default: // Do nothing because or it is a wrong Action number or it is an Ares/YR action... //Debug::Log("[%s] [%s] %d = %d,%d\n", pTeam->Type->ID, pScriptType->ID, pScript->idxCurrentLine, currentLineAction->Action, currentLineAction->Argument); @@ -2325,5 +2328,38 @@ TechnoClass* ScriptExt::FindBestObject(TechnoClass *pTechno, int method, int cal void ScriptExt::UnregisterGreatSuccess(TeamClass* pTeam) { pTeam->AchievedGreatSuccess = false; - pTeam->StepCompleted = true; // This action finished - FS-21 + pTeam->StepCompleted = true; +} + +void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) +{ + // This team has no units! END + if (!pTeam) + { + // This action finished + pTeam->StepCompleted = true; + Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d -> (Reason: No team members alive)\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); + + return; + } + + if (successPercentage < 0 || successPercentage > 100) + successPercentage = pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine].Argument; + + if (successPercentage < 0) + successPercentage = 0; + + if (successPercentage > 100) + successPercentage = 100; + + int percentage = ScenarioClass::Instance->Random.RandomRanged(0, 100); + + if (successPercentage <= percentage) + { + Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d -> (Reason: No team members alive)\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); + pTeam->CurrentScript->idxCurrentLine++; + } + + // This action finished + pTeam->StepCompleted = true; } diff --git a/src/Ext/Script/Body.h b/src/Ext/Script/Body.h index fad1de5091..a8f8bf914b 100644 --- a/src/Ext/Script/Body.h +++ b/src/Ext/Script/Body.h @@ -65,6 +65,7 @@ class ScriptExt static void UnregisterGreatSuccess(TeamClass * pTeam); static void Mission_Attack_List(TeamClass *pTeam, bool repeatAction, int calcThreatMode, int attackAITargetType); + static void SkipNextAction(TeamClass* pTeam, int successPercentage); static ExtContainer ExtMap; From 0f325539cd9580339c5982b6b32ca55b31b26338 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Thu, 28 Oct 2021 17:20:14 +0200 Subject: [PATCH 02/12] fix the percentage check --- 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 227e91267e..d9ab30a3b2 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2354,7 +2354,7 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) int percentage = ScenarioClass::Instance->Random.RandomRanged(0, 100); - if (successPercentage <= percentage) + if (percentage <= successPercentage) { Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d -> (Reason: No team members alive)\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); pTeam->CurrentScript->idxCurrentLine++; From e147011468ebbaa9d3768c4c9b673d5e70eb2ec9 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Thu, 28 Oct 2021 17:31:51 +0200 Subject: [PATCH 03/12] fix --- 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 d9ab30a3b2..e3afc2df50 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2352,7 +2352,7 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) if (successPercentage > 100) successPercentage = 100; - int percentage = ScenarioClass::Instance->Random.RandomRanged(0, 100); + int percentage = ScenarioClass::Instance->Random.RandomRanged(1, 100); if (percentage <= successPercentage) { From a07da3afc39944ec75724076489fc30fad59835f Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 14 Nov 2021 23:31:11 +0100 Subject: [PATCH 04/12] Small fix in a debug string --- 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 e3afc2df50..33e4cdd80e 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2338,7 +2338,7 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) { // This action finished pTeam->StepCompleted = true; - Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d -> (Reason: No team members alive)\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); + Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); return; } From 8180728b095f9c5d5fa67501a9df70dc2fe77d00 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 14 Nov 2021 23:37:45 +0100 Subject: [PATCH 05/12] fix string I modified the wrong string in the last commit --- 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 33e4cdd80e..b0c5d55c5a 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2338,7 +2338,7 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) { // This action finished pTeam->StepCompleted = true; - Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); + Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d -> (Reason: No team members alive)\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); return; } @@ -2356,7 +2356,7 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) if (percentage <= successPercentage) { - Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d -> (Reason: No team members alive)\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); + Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); pTeam->CurrentScript->idxCurrentLine++; } From b2d3d1a0d281024b33f6e969bbef29e5fd51e982 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Mon, 15 Nov 2021 16:53:59 +0100 Subject: [PATCH 06/12] point to latest YRpp --- YRpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YRpp b/YRpp index 5c5f811eaf..155dc5ac0f 160000 --- a/YRpp +++ b/YRpp @@ -1 +1 @@ -Subproject commit 5c5f811eaf6ab17876aa37b90f70c2172f8a83a5 +Subproject commit 155dc5ac0fc330ca03961fc9f68595dd7bef0cc6 From bfb2455001501ccfe449881d03f0321e0ccd22d2 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Wed, 24 Nov 2021 18:02:36 +0100 Subject: [PATCH 07/12] Update Body.cpp --- src/Ext/Script/Body.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index b37954dddf..61aca74114 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2343,7 +2343,9 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) { // This action finished pTeam->StepCompleted = true; - Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d -> (Reason: No team members alive)\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); + Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d -> (Reason: No team members alive)\n", + pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, + pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); return; } @@ -2361,7 +2363,9 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) if (percentage <= successPercentage) { - Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); + Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d\n", + pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, + pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); pTeam->CurrentScript->idxCurrentLine++; } @@ -2559,4 +2563,4 @@ void ScriptExt::VariableBinaryOperationHandler(TeamClass* pTeam, int nVariable, VariableOperationHandler(pTeam, nVariable, itr->second.Value); pTeam->StepCompleted = true; -} \ No newline at end of file +} From 96b5ba622cde41c194d46af77f0b5344b346a538 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Wed, 24 Nov 2021 19:31:59 +0100 Subject: [PATCH 08/12] Added the docs --- README.md | 2 +- docs/New-or-Enhanced-Logics.md | 11 +++++++++++ docs/Whats-New.md | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a2298fc516..d05523ec15 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Credits - **secsome (SEC-SOME)** - debug info dump hotkey, refactoring & porting of Ares helper code, introducing more Ares-derived stuff, disguise removal warhead, Mind Control removal warhead, Mind Control enhancement, shields, AnimList.PickRandom, MoveToCell fix, unlimited waypoints, Build At trigger action buildup anim fix, Undeploy building into a unit plays `EVA_NewRallyPointEstablished` fix, custom ore gathering anim, TemporaryClass related crash, Retry dialog on mission failure, Default disguise for individual InfantryTypes, PowerPlant Enhancer, SaveGame Trigger Action, QuickSave command, Numeric variables, Custom gravity for projectiles, Retint map actions bugfix - **Otamaa (Fahroni, BoredEXE)** - help with CellSpread, ported and fixed custom RadType code, togglable ElectricBolt bolts, customizable Chrono Locomotor properties per TechnoClass, DebrisMaximums fixes, Anim-to-Unit, NotHuman anim sequences improvements, Customizable OpenTopped Properties, hooks for ScriptType Actions 92 & 93, ore stage threshold for `HideIfNoOre` - **E1 Elite** - TileSet 255 and above bridge repair fix -- **FS-21** - Dump Object Info enhancements, Powered.KillSpawns, Spawner.LimitRange, ScriptType Actions 71, 72, 73, 74 to 81, 92, 93, 94, 95 to 98, 111, 112, MC deployer fixes, help with docs, Automatic Passenger Deletion +- **FS-21** - Dump Object Info enhancements, Powered.KillSpawns, Spawner.LimitRange, ScriptType Actions 71, 72, 73, 74 to 81, 92, 93, 94, 95 to 98, 111, 112, 113, MC deployer fixes, help with docs, Automatic Passenger Deletion - **AutoGavy** - interceptor logic, warhead critical damage system - **ChrisLv_CN** - interceptor logic, LaserTrails, laser fixes, general assistance (work relicensed under [following permission](images/ChrisLv-relicense.png)) - **Xkein** - general assistance, YRpp edits diff --git a/docs/New-or-Enhanced-Logics.md b/docs/New-or-Enhanced-Logics.md index d02f12257e..9a8d56a7fe 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -952,6 +952,17 @@ In `aimd.ini`: [SOMESCRIPTTYPE] ; ScriptType x=112,n ``` + +### `113` Randomly Skip Next Action + +- When executed this action picks a random value between 1 and 100. If the value is equal or below the second parameter then the next action will be skipped. If the second parameter is 0 means that the next action will never be skipped and 100 means thay always will be skipped. + +In `aimd.ini`: +```ini +[SOMESCRIPTTYPE] ; ScriptType +x=113,n ; where 0 > n <= 100 +``` + ### `500 - 523` Edit Variable - Operate a variable's value - The variable's value type is int16 instead of int32 in trigger actions for some reason, which means it ranges from -2^15 to 2^15-1. diff --git a/docs/Whats-New.md b/docs/Whats-New.md index 328d0a0cad..f22ea95a6e 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -246,6 +246,7 @@ New: - Attached animation layer customization (by Starkku) - Jumpjet unit layer deviation customization (by Starkku) - IsSimpleDeployer deploy direction & animation customizations (by Starkku) +- Script Action 113 to Randomly Skip Next Action (by FS-21) Vanilla fixes: - Fixed laser drawing code to allow for thicker lasers in house color draw mode (by Kerbiter, ChrisLv_CN) From 10d7dd013ebc6a49063dd9db3c884a53bda4d1d0 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 28 Nov 2021 18:13:34 +0100 Subject: [PATCH 09/12] small tweak --- src/Ext/Script/Body.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index 61aca74114..111889d90e 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2343,9 +2343,10 @@ void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) { // This action finished pTeam->StepCompleted = true; - Debug::Log("DEBUG: ScripType: [%s] [%s] Jump to NEXT line: %d = %d,%d -> (Reason: No team members alive)\n", - pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine + 1, - pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); + Debug::Log("DEBUG: [%s] [%s] (line: %d) Jump to next line: %d = %d,%d -> (No team members alive)\n", + pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, + pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, + pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); return; } From d15da5c76ebfc76af6615366d89b94764e10c6c1 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Tue, 30 Nov 2021 12:32:06 +0100 Subject: [PATCH 10/12] improvement for unknown actions --- src/Ext/Script/Body.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index 111889d90e..2f09d08357 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -148,7 +148,12 @@ void ScriptExt::ProcessAction(TeamClass* pTeam) break; default: // Do nothing because or it is a wrong Action number or it is an Ares/YR action... - //Debug::Log("[%s] [%s] %d = %d,%d\n", pTeam->Type->ID, pScriptType->ID, pScript->idxCurrentLine, currentLineAction->Action, currentLineAction->Argument); + if (action > 70 && !(action >= PhobosScripts::LocalVariableAdd && action <= PhobosScripts::GlobalVariableAndByGlobal)) + { + // Unknown new action. This action finished + pTeam->StepCompleted = true; + Debug::Log("[%s] [%s] (line %d): Unknown Script Action: %d\n", pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine].Action); + } break; } From 5cf60d1669f35c20caea424cac487191d0669b5a Mon Sep 17 00:00:00 2001 From: FS-21 Date: Wed, 5 Jan 2022 00:30:10 +0100 Subject: [PATCH 11/12] Grouping actions in docs --- docs/Whats-New.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Whats-New.md b/docs/Whats-New.md index f22ea95a6e..7c0ea96785 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -238,6 +238,7 @@ New: - Script Action 95 to 98 for new AI movements towards certain objects (by FS-21) - Script Action 111 that un-register Team success, is just the opposite effect of Action 49 (by FS-21) - Script Action 112 to regroup temporarily around the Team Leader (by FS-21) +- Script Action 113 to Randomly Skip Next Action (by FS-21) - ObjectInfo now shows current Target and AI Trigger data (by FS-21) - Shield absorption and passthrough customization (by Morton) - Limbo Delivery of buildings (by Morton) @@ -246,7 +247,6 @@ New: - Attached animation layer customization (by Starkku) - Jumpjet unit layer deviation customization (by Starkku) - IsSimpleDeployer deploy direction & animation customizations (by Starkku) -- Script Action 113 to Randomly Skip Next Action (by FS-21) Vanilla fixes: - Fixed laser drawing code to allow for thicker lasers in house color draw mode (by Kerbiter, ChrisLv_CN) From 8ea36877de9f04349b48a90f468bdf962ac1f0b1 Mon Sep 17 00:00:00 2001 From: Metadorius Date: Fri, 7 Jan 2022 00:18:10 +0200 Subject: [PATCH 12/12] Reorder functions --- src/Ext/Script/Body.cpp | 78 ++++++++++++++++++++--------------------- src/Ext/Script/Body.h | 2 +- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Ext/Script/Body.cpp b/src/Ext/Script/Body.cpp index 5c0ed6d2f3..32c5e8b7e8 100644 --- a/src/Ext/Script/Body.cpp +++ b/src/Ext/Script/Body.cpp @@ -2541,44 +2541,6 @@ void ScriptExt::UnregisterGreatSuccess(TeamClass* pTeam) pTeam->StepCompleted = true; } -void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) -{ - // This team has no units! END - if (!pTeam) - { - // This action finished - pTeam->StepCompleted = true; - Debug::Log("DEBUG: [%s] [%s] (line: %d) Jump to next line: %d = %d,%d -> (No team members alive)\n", - pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, - pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, - pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); - - return; - } - - if (successPercentage < 0 || successPercentage > 100) - successPercentage = pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine].Argument; - - if (successPercentage < 0) - successPercentage = 0; - - if (successPercentage > 100) - successPercentage = 100; - - int percentage = ScenarioClass::Instance->Random.RandomRanged(1, 100); - - if (percentage <= successPercentage) - { - Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d\n", - pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, - pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); - pTeam->CurrentScript->idxCurrentLine++; - } - - // This action finished - pTeam->StepCompleted = true; -} - void ScriptExt::SetMoveMissionEndMode(TeamClass* pTeam, int mode = 0) { // This passive method replaces the CloseEnough value from rulesmd.ini by a custom one. Used by Mission_Move() @@ -2717,6 +2679,45 @@ bool ScriptExt::MoveMissionEndStatus(TeamClass* pTeam, TechnoClass* pFocus, Foot return bForceNextAction; } + +void ScriptExt::SkipNextAction(TeamClass* pTeam, int successPercentage = 0) +{ + // This team has no units! END + if (!pTeam) + { + // This action finished + pTeam->StepCompleted = true; + Debug::Log("DEBUG: [%s] [%s] (line: %d) Jump to next line: %d = %d,%d -> (No team members alive)\n", + pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, + pTeam->CurrentScript->idxCurrentLine + 1, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Action, + pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 1].Argument); + + return; + } + + if (successPercentage < 0 || successPercentage > 100) + successPercentage = pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine].Argument; + + if (successPercentage < 0) + successPercentage = 0; + + if (successPercentage > 100) + successPercentage = 100; + + int percentage = ScenarioClass::Instance->Random.RandomRanged(1, 100); + + if (percentage <= successPercentage) + { + Debug::Log("DEBUG: ScripType: [%s] [%s] (line: %d) Next script line skipped successfuly. Next line will be: %d = %d,%d\n", + pTeam->Type->ID, pTeam->CurrentScript->Type->ID, pTeam->CurrentScript->idxCurrentLine, pTeam->CurrentScript->idxCurrentLine + 2, + pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Action, pTeam->CurrentScript->Type->ScriptActions[pTeam->CurrentScript->idxCurrentLine + 2].Argument); + pTeam->CurrentScript->idxCurrentLine++; + } + + // This action finished + pTeam->StepCompleted = true; +} + void ScriptExt::VariablesHandler(TeamClass* pTeam, PhobosScripts eAction, int nArg) { struct operation_set { int operator()(const int& a, const int& b) { return b; } }; @@ -2953,4 +2954,3 @@ FootClass* ScriptExt::FindTheTeamLeader(TeamClass* pTeam) return pLeaderUnit; } - diff --git a/src/Ext/Script/Body.h b/src/Ext/Script/Body.h index 01fadc308d..1d66464240 100644 --- a/src/Ext/Script/Body.h +++ b/src/Ext/Script/Body.h @@ -142,12 +142,12 @@ class ScriptExt static void UnregisterGreatSuccess(TeamClass * pTeam); static void Mission_Attack_List(TeamClass *pTeam, bool repeatAction, int calcThreatMode, int attackAITargetType); - static void SkipNextAction(TeamClass* pTeam, int successPercentage); static void Mission_Attack_List1Random(TeamClass *pTeam, bool repeatAction, int calcThreatMode, int attackAITargetType); static void Mission_Move_List(TeamClass *pTeam, int calcThreatMode, bool pickAllies, int attackAITargetType); static void Mission_Move_List1Random(TeamClass *pTeam, int calcThreatMode, bool pickAllies, int attackAITargetType, int idxAITargetTypeItem); static void SetCloseEnoughDistance(TeamClass *pTeam, double distance); static void SetMoveMissionEndMode(TeamClass* pTeam, int mode); + static void SkipNextAction(TeamClass* pTeam, int successPercentage); static void VariablesHandler(TeamClass* pTeam, PhobosScripts eAction, int nArg); template