This is a quite simple feature request. Two new commands:
SetDestination and
GetDestination.
[Unit UID] [Destination X] [Destination Y] SetDestination
[Unit UID] GetDestination -- [Origin X] [Origin Y] [Destination X] [Destination Y]So, you know how we can move units around?
SetDestination takes a unit and sets its destination to somewhere else. This would only work on blasters, mortars, CNs, beams, and so on - but might, depending on the preference of Grand Master V, allow us to make a unit that, for a price, will move reactors, collectors, forges, and so on. Of course, emitters and such can't do this.
And
GetDestination selects a unit then tells us where it's moving to. And if either of the latter outputs are -1, then it's not moving. And if it's not moving, then the Origin outputs, when combined with a couple of
pops, makes the command act like a GetUnitAt function in reverse. It would also be useful for a security thing: when a moving units gets too close, a CRPLcore makes it start going back to where it came from! And the ocde for that would be like so:
Spoiler
@GetClosestUnit # A function to get the UID of the closest unit within a radius of the core
<-closestUnit neq0 if
<-closestUnit GetDestination -1 neq if
pop ->origY ->origX
<-closestUnit <-origX <-origY SetDestination
else
ClearStack
endif
endif
So - any thoughts?
Not a fan of altering player input. If I send my units somewhere, I want them to go exactly to that place and not to be redirected.
Quote from: eduran on February 03, 2014, 06:07:58 AM
Not a fan of altering player input. If I send my units somewhere, I want them to go exactly to that place and not to be redirected.
Only a horribly irresponsible map maker would do that without warning. Anyway, you can still destroy, remove ammo, lower health, and simply insta-move player units elsewhere. It's not like this function would really change how much power a map maker has.
But it could also be more useful - eg allowing units to gracefully move into the void.
This falls under what I consider unit command APIs. I added one very recently, the ScriptVar support on guppies to set and get the mode.
A more complete set of unit command APIs would allow changing the modes of all units that support them, as well as ordering units that can move, to move (that includes flying units).
These APIs might be interesting in a few scenarios... maybe. Someone could try to make a self playing map that moved things around to play the game for you.... or stuff like that. But the work and effort it would take on my part and the potential rewards for map makers seems a little out of balance, which is why I've not added them.
Quote from: virgilw on February 03, 2014, 01:32:57 PM
These APIs might be interesting in a few scenarios... maybe. Someone could try to make a self playing map that moved things around to play the game for you.... or stuff like that. But the work and effort it would take on my part and the potential rewards for map makers seems a little out of balance, which is why I've not added them.
If these APIs can work on CRPL, the reward will far more than expected, although the effort it takes also far more than expected :P
Back to the topic, I don't think this API is very useful. If we can make a CRPL move and control same as other units, then we can simply hook the mouse click on the units and apply the script to the unit to achieve all these.
Quote from: kai on February 04, 2014, 03:02:35 AM
Quote from: virgilw on February 03, 2014, 01:32:57 PM
These APIs might be interesting in a few scenarios... maybe. Someone could try to make a self playing map that moved things around to play the game for you.... or stuff like that. But the work and effort it would take on my part and the potential rewards for map makers seems a little out of balance, which is why I've not added them.
If these APIs can work on CRPL, the reward will far more than expected, although the effort it takes also far more than expected :P
Back to the topic, I don't think this API is very useful. If we can make a CRPL move and control same as other units, then we can simply hook the mouse click on the units and apply the script to the unit to achieve all these.
It's the GetDestination that I'm more interested in.
I tried to mak GetDestination, but obviously impossible...
This is my second try, which cannot handle multiple unit moving at the same time, nor change destination while moving:
once
ShowTraceLog
0 ->switchCounter
CreateList ->flyingUnitList
CreateList ->destListx
CreateList ->destListy
endonce
ClearTraceLog
@test2
:test2
if (GetMouseButtonDown(0))
do (GetAllUnitsInRange(0 0 9999 FALSE) 0)
->unitUID
if(GetUnitAttribute(<-unitUID CONST_ISLANDED) eq0)
FALSE ->isUnitFlying
do(GetListCount(<-flyingUnitList) 0)
if(eq(<-unitUID GetListElement(<-flyingUnitList I)))
TRUE ->isUnitFlying
Break
endif
loop
if(not(<-isUnitFlying))
AppendToList(<-flyingUnitList <-unitUID)
<-destListx GetMouseCell <-destListy swap AppendToList AppendToList
endif
endif
loop
endif
#update list
0 ->i
while <-i lt(GetListCount(<-flyingUnitList)) repeat
if(GetUnitAttribute(GetListElement(<-flyingUnitList <-i) CONST_ISLANDED) eq(TRUE))
RemoveListElement(<-flyingUnitList <-i)
RemoveListElement(<-destListx <-i)
RemoveListElement(<-destListy <-i)
else
add(<-i 1) ->i
endif
endwhile
#debug output
do(GetListCount(<-flyingUnitList) 0)
Trace3(GetListElement(<-flyingUnitList I) GetListElement(<-destListx I) GetListElement(<-destListy I))
loop
:Awake
OperateWhilePaused(true)