-
Notifications
You must be signed in to change notification settings - Fork 650
Mission API - Move/Rotate Unit Actions #8541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Damgam
wants to merge
7
commits into
mission-api/dev
Choose a base branch
from
mission-api-move-unit
base: mission-api/dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d20a000
Mission API - Move/Rotate Unit Actions
Damgam 74d7721
Changes following review
Damgam d5f8050
When you copy stuff without fully realising what it does.
Damgam 8becd72
Nevermind we do need this just without table copy.
Damgam d2b967c
.
Damgam f23c3e1
gate 0,0,0 direction from executing as it's causing errors.
Damgam f385b82
More Fencing.
Damgam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| local ParameterTypes = GG['MissionAPI'].Modules.ParameterTypes.Types | ||
|
|
||
| local function moveUnits(unitName, position, direction, randomRadius) | ||
| local tracking = GG['MissionAPI'].Modules.Tracking | ||
| if tracking.IsUnitNameUntracked(unitName) then return end | ||
|
|
||
| local trackedUnitIDs = GG['MissionAPI'].trackedUnitIDs[unitName] | ||
|
|
||
| for unitID in pairs(trackedUnitIDs) do | ||
| if Spring.GetUnitIsDead(unitID) == false then | ||
| if randomRadius and randomRadius > 0 then | ||
| local randomRadius = math.ceil(randomRadius) | ||
| Spring.SetUnitPosition(unitID, position.x+math.random(-randomRadius, randomRadius), position.y, position.z+math.random(-randomRadius, randomRadius)) | ||
| else | ||
| Spring.SetUnitPosition(unitID, position.x, position.y, position.z) | ||
| end | ||
|
|
||
| if direction then | ||
| local testposx, _, testposz = Spring.GetUnitPosition(unitID) | ||
| if not (math.abs(direction.x-testposx) > 0.001 and math.abs(direction.z-testposz) > 0.001) then | ||
| Spring.SetUnitDirection(unitID, direction.x-testposx, direction.y, direction.z-testposz) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return { | ||
| { | ||
| type = 'MoveUnits', | ||
| parameters = { | ||
| { name = 'unitName', required = true, type = ParameterTypes.UnitName }, | ||
| { name = 'position', required = true, type = ParameterTypes.Position }, | ||
| { name = 'direction', required = false, type = ParameterTypes.Position }, -- Point on the map towards which the unit rotates | ||
| { name = 'randomRadius', required = false, type = ParameterTypes.Number }, -- Spread teleported units around in radius this big. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a radius. It is a half-length of a side of a map-aligned box.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }, | ||
| actionFunction = moveUnits, | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| local ParameterTypes = GG['MissionAPI'].Modules.ParameterTypes.Types | ||
|
|
||
| local function rotateUnits(unitName, direction) | ||
| local tracking = GG['MissionAPI'].Modules.Tracking | ||
| if tracking.IsUnitNameUntracked(unitName) then return end | ||
|
|
||
| local trackedUnitIDs = GG['MissionAPI'].trackedUnitIDs[unitName] | ||
|
|
||
| for unitID in pairs(trackedUnitIDs) do | ||
| if Spring.GetUnitIsDead(unitID) == false then | ||
| if direction then | ||
| local testposx, _, testposz = Spring.GetUnitPosition(unitID) | ||
|
Damgam marked this conversation as resolved.
|
||
| if not (math.abs(direction.x-testposx) >= 0.001 and math.abs(direction.z-testposz) >= 0.001) then | ||
| Spring.SetUnitDirection(unitID, direction.x-testposx, direction.y, direction.z-testposz) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return { | ||
| { | ||
| type = 'RotateUnits', | ||
| parameters = { | ||
| { name = 'unitName', required = true, type = ParameterTypes.UnitName }, | ||
| { name = 'direction', required = true, type = ParameterTypes.Position }, -- Point on the map towards which the unit rotates | ||
| }, | ||
| actionFunction = rotateUnits, | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| local triggerTypes = GG['MissionAPI'].TriggerTypes | ||
| local actionTypes = GG['MissionAPI'].ActionDefinitions.Types | ||
|
|
||
| local triggers = { | ||
| spawnTanks = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| gameFrame = 90, | ||
| }, | ||
| actions = { 'spawnTanks' }, | ||
| }, | ||
|
|
||
| teleportTanksWithoutSetDirection = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| gameFrame = 150, | ||
| }, | ||
| actions = { 'teleportTanksWithoutSetDirection1' }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection1 = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| gameFrame = 300, | ||
| }, | ||
| actions = { 'teleportTanksWithSetDirection1' }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection2 = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| gameFrame = 450, | ||
| }, | ||
| actions = { 'teleportTanksWithSetDirection2' }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection3 = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| gameFrame = 600, | ||
| }, | ||
| actions = { 'teleportTanksWithSetDirection3' }, | ||
| }, | ||
|
|
||
| teleportTanksWithoutSetDirection2 = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| gameFrame = 750, | ||
| }, | ||
| actions = { 'teleportTanksWithoutSetDirection1' }, | ||
| }, | ||
|
|
||
| rotateTanksTowardsCenterOfTheGroup = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| gameFrame = 900, | ||
| }, | ||
| actions = { 'rotateTanksTowardsCenterOfTheGroup' }, | ||
| }, | ||
| } | ||
|
|
||
| local actions = { | ||
|
|
||
| spawnTanks = { | ||
| type = actionTypes.SpawnUnits, | ||
| parameters = { | ||
| unitLoadout = { | ||
| { | ||
| unitDefName = 'armstump', | ||
| x = 2300, | ||
| z = 1900, | ||
| team = 0, | ||
| unitName = 'tanks', | ||
| quantity = 10 | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| teleportTanksWithoutSetDirection1 = { | ||
| type = actionTypes.MoveUnits, | ||
| parameters = { | ||
| unitName = "tanks", | ||
| position = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| randomRadius = 300, | ||
| }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection1 = { | ||
| type = actionTypes.MoveUnits, | ||
| parameters = { | ||
| unitName = "tanks", | ||
| position = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| direction = { | ||
| x = 3000, | ||
| z = 3000, | ||
| }, | ||
| randomRadius = 300, | ||
| }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection2 = { | ||
| type = actionTypes.MoveUnits, | ||
| parameters = { | ||
| unitName = "tanks", | ||
| position = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| direction = { | ||
| x = 1000, | ||
| z = 1000, | ||
| }, | ||
| randomRadius = 300, | ||
| }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection3 = { | ||
| type = actionTypes.MoveUnits, | ||
| parameters = { | ||
| unitName = "tanks", | ||
| position = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| direction = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| randomRadius = 300, | ||
| }, | ||
| }, | ||
|
|
||
| rotateTanksTowardsCenterOfTheGroup = { | ||
| type = actionTypes.RotateUnits, | ||
| parameters = { | ||
| unitName = "tanks", | ||
| direction = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| } | ||
|
|
||
| return { | ||
| Triggers = triggers, | ||
| Actions = actions, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.