Posted By
|
Message
|
SolarB
Registered 26/12/2011
Points 564
|
13th March, 2012 at 13/03/2012 14:56:49 -
I have a unit with health x and I have multiple medics. I want each medic to go and heal the unit with the lowest health, but if there's already a medic on one unit I want him to go and heal the next one.
The Select Object extension works fine but how would I go about selecting the NEXT lowest value?
Any other solutions not using the Select Object extension would also be greatly appreciated.
My Open Source Examples: http://bit.ly/YyUFUh
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
13th March, 2012 at 13/03/2012 16:13:06 -
Give each unit a flag to indicate whether it has been targeted by a medic. Then you can pick the unit with its flag off, that has the lowest value.
Something along the lines of:
+ Always
-> ForEach: Start ForEach loop for Medic
+ ForEach: On Foreach loop for Medic
+ Unit: Flag0 is OFF
+ SelectObject: Select Unit with lowest Health
-> Medic: target the selected unit...
-> Unit: Set Flag0 to ON
However, instead of just healing the unit with the lowest health, you'll probably want to use some combination of health and distance - otherwise you might have medics wandering half way across the map to heal a unit, when there's another damaged unit right next to them, which is then going to have to be targeted by a different medic.
n/a
|
SolarB
Registered 26/12/2011
Points 564
|
13th March, 2012 at 13/03/2012 16:28:37 -
Argh why didn't I think of that? Cheers Sketchy.
I'm thinking distance could be done with the Adv. Dir. Object, i.e.
before loop:
getfixed + distance of unit to medic
on loop:
flag is OFF
fixed 'unit' = getfixed 0 adv.dir
select lowest...etc.
is this sound?
Btw and more importantly any idea how to make the medic stop near the unit but not overlap it? I'm using your RTS movement code for all units including the medic but of course when the healing loop happens the medic sets TarX & TarY to the unit. Currently he just overlaps it. Your thoughts?
Thanks!
My Open Source Examples: http://bit.ly/YyUFUh
|
Sketchy Cornwall UK
Registered 06/11/2004
Points 1971
|
14th March, 2012 at 14/03/2012 00:17:38 -
Not sure I understand, but give it a try and see how it goes
For stopping the medic overlapping the unit, you need to check the distance between them, and then if it's close, set the target position to its current position to stop it moving.
It could still overlap other units though - I don't know of any way to handle pathfinding for multiple objects without any of them ever overlapping - it certainly wouldn't be easy.
n/a
|
SolarB
Registered 26/12/2011
Points 564
|
14th March, 2012 at 14/03/2012 15:33:51 -
Thanks Sketchy, overlapping and distance are not a problem as yet but...
I had some problems making the medic stick to the unit and not instantly leap to another one after only healing it a little bit. Almost resolved - here's a rough working out - but why is there still more than one medic per unit? In another version I had, when there were more than 4 medics and soldiers one soldier was always left to die argh!
http://www.mediafire.com/?3115ah8ed41r48i
My Open Source Examples: http://bit.ly/YyUFUh
|
|
|