Autoplacement of units on a map. - Page 2

Autoplacement of units on a map.

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Autoplacement of units on a map.

Post by Argh »

The easiest way to do this, in general, is simply to kill the Unit, and create a new Unit for that Team at the endpoint. To make it fancier, add a timing equation, to make it take some time (i.e., for each element "underground", subtract a frame from "traveling time", etc.), and store the "traveling" Units in a Lua table:

Code: Select all

travelUnits = {unitDefID,timeTraveling,destination,team}

function gadget:GameFrame(f)
if f + 4 % 5 < 0.01 then
  for i,k in ipairs(travelUnits) do
    if k.timeTraveling - f <= 0 then
      Spring.CreateUnit(k.unitDefID,k.destination XYZ,0,k.team)
    else
      k.timeTraveling = k.timeTraveling - 4
    end
  end
end
That's pretty much it, for the basic game logic, other than writing the search that the tunnels need to perform, to find candidates. You can get much fancier, of course, depending on game rules, etc., but that's a straightforward case.

Then you just need to define the destinations, and then write some equally-simple code to store Units if they enter certain places on the map, and set their destination. Obviously, this gets more complicated if you want tunnels you can "steer", but you were referring to static ones, so there you go.

To avoid logic problems, I'd also give them a "just been transported" tag that is wiped with time, or only let them actually be transported if their current Move / Fight / Patrol order takes them to a valid transport point (i.e., Units that have just been Transported will just sit there, they'll only go "down the tunnel" if they have appropriate orders).

The only tricky part of that might be getting the orders. This might work:

Code: Select all

  local queue = Spring.GetCommandQueue(targetID);
  if (queue ~= nil) then
    if queue[1].id == CMD.MOVE or CMD.FIGHT or CMD.PATROL then
      local params = queue[1].params
      local x,y,z = params[1],params[2],params[3]
      -- do some search logic here, based on the position of the tunnel, if x,y,z are close to the tunnel, then go ahead and remove the Unit
    end
  end
So, you basically just need to write the search logic, build your destinations, write some snazzy visual / audio effects for said event, etc., and you're good to go.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Autoplacement of units on a map.

Post by Tribulex »

lurker wrote:KP wipes out the units to full health. Will tunnels take time to go along?
I dont think so. It complicates gameplay too much, because then there has to be a gui to move units underground between bunkers. I don't want to over-complicate gameplay.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Autoplacement of units on a map.

Post by Argh »

That code I wrote you imposes a time-cost for moving through a tunnel, and doesn't use a UI, lol. The only reason you'd need a UI control for end-users is if you want them to pick which tunnel their troops exit from.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Autoplacement of units on a map.

Post by Tribulex »

Basically, these are ant hills, and my units are ants, of various types etc.

The ant hill serves as storage for ants. As such, a transport model would be perfect, and also easy to implement.

Its important to be able to select an anthill and have some icons you can click, shift click, etc. and then the units of that type come out. There would be numbers etc.

I could implement a common pool to these ant hills, and then all the units of that type would suddenly appear, thats easy enough. However, transport times might be confusing if I store each ant at a certain hill and calculate travel times. It might just be easier having a built-in delay in how long it takes for the ants to come out of the hill.
Post Reply

Return to “Lua Scripts”