Best way to get nearest unit of a certain type

Best way to get nearest unit of a certain type

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Best way to get nearest unit of a certain type

Post by Jools »

I'm thinking of adding a feature to my map, namely that if a team is in the possession of a certain alien unit, then other aliens are more likely to join that team (maybe depending on distance to it). Would this function do it?

Code: Select all

Spring.GetTeamUnitsByDefs

 ( number teamID, number unitDefID | { number unitDefID1, ... } )
   -> nil | unitTable = { [1] = number unitID, etc... }
Do I supply the team id and unitDefID and then get just a number in return? I'm sorry but the description is a bit unclear.

The other way would be to store this information in a table when this other unit is created, would that be faster and more efficient than to lookup the value dynamically when a unit is created from a meteorite? Or should I try to minimise the amount of static variables in a gadget instead?

Sorry if this is a stupid question.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: Best way to get nearest unit of a certain type

Post by FLOZi »

You supply the teamID and unitDefID and get a TABLE of the units of that unitdef on that team.

IMO I'd go with this method and see how it works, unless you're spawning aliens many times a second I don't see it being a problem.
Post Reply

Return to “Game Development”