-
Notifications
You must be signed in to change notification settings - Fork 651
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
base: mission-api/dev
Are you sure you want to change the base?
Changes from all commits
d20a000
74d7721
d5f8050
8becd72
d2b967c
f23c3e1
f385b82
8633b78
09e35a8
ea08b56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 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 | ||
| Spring.SetUnitPosition(unitID, position.x, position.y, position.z) | ||
| if direction then | ||
| local testposx, _, testposz = Spring.GetUnitPosition(unitID) | ||
| if math.abs(direction.x-testposx) > 0.001 or 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 | ||
| }, | ||
| actionFunction = moveUnits, | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 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) | ||
| if math.abs(direction.x-testposx) >= 0.001 or 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 | ||
|
Member
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. Why are we using such an indirect method of specifying rotation? Shouldn't this just be 0°-360°?
Member
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. Sorry, I missed hitting the submit review button, I thought this had posted.
Member
Author
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. Because that's the only way Spring/Recoil provides as far as I can tell. The other "rotation" thing seem to be for aircrafts only from my tests. But also if you think about it, it's actually very user friendly. "You sit here, look at that position." instead of thinking how many degrees it's gonna be.
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. @WatchTheFort you have to be more explicit, damgam doesn't intuitively know that an angle is equivalent to a class of vectors so you'll have to give him a hint on how to derive a vector (or alternatively give him a link to the docs for the other Spring function which does accept an angle).
Member
Author
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. I still think this is better than explicitly giving it degrees, but whatever.
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. My 2c:
Member
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. We can overload the parameter here, if a single value is passed, that is an angle, if a coordinate pair is passed, that's a direction vector.
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. What if you come up with more variants later?
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.
How do you feel about the face-toward-point parameter, then?
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.
Sounds good
I agree
Is there a case where a rectangular def might need both to move and rotate at once? edit: or rotate-then-move, e.g. if a building will flatten terrain |
||
| }, | ||
| actionFunction = rotateUnits, | ||
| }, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| local triggerTypes = GG['MissionAPI'].TriggerDefinitions.Types | ||
| local actionTypes = GG['MissionAPI'].ActionDefinitions.Types | ||
|
|
||
| local triggers = { | ||
| spawnTanks = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| seconds = 3, | ||
| }, | ||
| actions = { 'spawnTanks' }, | ||
| }, | ||
|
|
||
| teleportTanksWithoutSetDirection = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| seconds = 5, | ||
| }, | ||
| actions = { 'teleportTanksWithoutSetDirection1' }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection1 = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| seconds = 10, | ||
| }, | ||
| actions = { 'teleportTanksWithSetDirection1' }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection2 = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| seconds = 15, | ||
| }, | ||
| actions = { 'teleportTanksWithSetDirection2' }, | ||
| }, | ||
|
|
||
| teleportTanksWithoutSetDirection2 = { | ||
| type = triggerTypes.TimeElapsed, | ||
| parameters = { | ||
| seconds = 25, | ||
| }, | ||
| actions = { 'teleportTanksWithoutSetDirection1' }, | ||
| }, | ||
| } | ||
|
|
||
| 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, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection1 = { | ||
| type = actionTypes.MoveUnits, | ||
| parameters = { | ||
| unitName = "tanks", | ||
| position = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| direction = { | ||
| x = 3000, | ||
| z = 3000, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| teleportTanksWithSetDirection2 = { | ||
| type = actionTypes.MoveUnits, | ||
| parameters = { | ||
| unitName = "tanks", | ||
| position = { | ||
| x = 2500, | ||
| z = 2000, | ||
| }, | ||
| direction = { | ||
| x = 1000, | ||
| z = 1000, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| } | ||
|
|
||
| return { | ||
| Triggers = triggers, | ||
| Actions = actions, | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.