Author Topic: [done] position check  (Read 1038 times)

treba

  • Guest
[done] position check
« on: 9 October 2012, 19:20:22 »
hey,

i'd like to request a lua query that checks whether a position is already occupied by another unit. it can be a simple bool like isPositionOccupied() or a query for a unit, like unitAtPosition(), that gives back a nil if the field is free.

i'm currently building a network scenario (to get my editor into shape) that is based on footmen frenzy, but to get that working properly i have to be able to spawn units with createUnit. unfortunatly i don't have a way, yet, to be sure that this happened. atleast afaik.

greetings,
treba
« Last Edit: 10 October 2012, 05:53:32 by softcoder »

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: position check
« Reply #1 on: 9 October 2012, 20:03:32 »
svn has the following two new lua functions waiting for you to test:

bool isFreeCellsOrHasUnit(Vec2i pos, int field, int unitId)
bool isFreeCells(Vec2i pos, int unitSize, int field)

The first function checks the cell to see if an already existing unit can occupy the cell position (in the field specified by field).
Field values: 0 = land, 1 = air

The second function checks the cell position to see if a unit of size unitsize can occupy the field specified in field.

treba

  • Guest
Re: position check
« Reply #2 on: 9 October 2012, 20:11:57 »
wow thanks alot!

edit:

i tried the following:
Code: [Select]
createUnit('swordman', 0, startLocation(0))
if isFreeCells(startLocation(0), 1, 0) then
    addConsoleText('empty')
else
    addConsoleText('full')
end
and
Code: [Select]
createUnit('swordman', 0, startLocation(0))
if isFreeCellsOrHasUnit(startLocation(0), 0, lastCreatedUnit()) then
    addConsoleText('empty')
else
    addConsoleText('full')
end

both always returned true/empty. do you have a guess why?
« Last Edit: 10 October 2012, 11:38:38 by treba »

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: [done] position check
« Reply #3 on: 10 October 2012, 18:43:45 »
You are using the start location, but its likely the units are NOT in the start location. There is another method to get the unit's location:

Vec2i getUnitPosition(int unitId)

Try that and see what you get.

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Re: [done] position check
« Reply #4 on: 10 October 2012, 19:57:41 »
Just made some bug fixes for the free cell functions (parameter order changed also and notice you MUST check for 1 or 0 return value):

                        if isFreeCells(1,0,unitPosition(lastCreatedUnit())) == 1 then 
                            print('empty')
                        else
                            print('full')
                        end