Author Topic: Lua function needed  (Read 1675 times)

wciow

  • Behemoth
  • *******
  • Posts: 968
    • View Profile
Lua function needed
« on: 9 August 2009, 09:04:30 »
Can anyone write a Lua function which checks a specified cell to see if there is a unit on it and returns the units faction?

Just one catch . . .

You can't use any unit id to specify a unit.

If anyone knows how to do this please tell me.
Check out my new Goblin faction - https://forum.megaglest.org/index.php?topic=9658.0

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Re: Lua function needed
« Reply #1 on: 9 August 2009, 09:15:52 »
You mean something like?:
factionId isCellOccupied(Vec2i)

Or more like?:
factionId unitOnCell(unitType, Vec2i)
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: Lua function needed
« Reply #2 on: 9 August 2009, 12:53:28 »
Maybe you can go through all units and test their positions ( with lua )...
But some units are bigger than one cell coordinate.
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Lua function needed
« Reply #3 on: 9 August 2009, 13:14:44 »
Maybe you can go through all units and test their positions ( with lua )...
But some units are bigger than one cell coordinate.

Yep, this would be the only way to do it currently. You'd need to record every unit created, storing their IDs in a table, then loop over it testing the position of every unit... pretty intensive processing to be doing with LUA. (and the size problem... if you really wanted it to be single cell accurate).
Glest Advanced Engine - Code Monkey

Timeline | Downloads

wciow

  • Behemoth
  • *******
  • Posts: 968
    • View Profile
Re: Lua function needed
« Reply #4 on: 9 August 2009, 18:43:48 »
OK thanks guys.

I had an idea similar to Silnarm's but also realised that it would take way too much cpu.

I suppose its another thing to add to the long todo list.
Check out my new Goblin faction - https://forum.megaglest.org/index.php?topic=9658.0