Jump to content
Dr_Cox1911

IsoCell: Get free tile outside of building

Recommended Posts

I'm currently looking for a clever way of getting a free IsoGridSquare out in the open of a IsoCell.

I found the method IsoCell:getFreeTile(RoomDef paramRoomDef), but as this states it needs a RoomDef. I don't really know where I could get a RoomDef that represents the "outside-world".

 

So do you guys know any clever way of doing this? I could randomly choose tiles within the IsoCell and check them, but is this really the way to go?

Share this post


Link to post
Share on other sites

Is it not feasible to implement the code from getFreeTile() in lua?
The code for the method is pretty simplistic, and it appears the whole reason for the RoomDef (least inside of the method) is so there's a bounding box to check.

 

Totally untested and quickly ported from java, so apologies if i missed something:

-- lua version of IsoCell.getFreeTile() but with a manually specified
-- bounding box instead of using a RoomDef
function getFreeTile(cell, start_x, end_x, start_y, end_y, z)
    local free = {}
    for x=start_x, end_x do
        for y=start_y, end_y do
            local square = cell:getGridSquare(x, y, z)
            if square then
                square:setCachedIsFree(false)
                square:setCacheIsFree(false)
                if (square:isFree(false)) then  
                    table.insert(free, square)
                end
            end
        end
    end
    if #free == 0 then return end
    return free[ZombRand(#free) + 1]
end

 

Edited by Fenris_Wolf

Share this post


Link to post
Share on other sites

Not really sure the system would scale well at all, in Lua or Java side. Least not if it needs to run during time-critical events.

 

Also note the IsoCell.getGridSquare() method takes different routes (and thus performance differences) depending if its run on the server or not. Naturally, i haven't tested the performance differences so can't say with 100% certainty, but the servers method looks far more efficient.

 

Optimizations could be made to improve performance, that lua port of the function above is pretty un-optimal. Returning the first free tile would be a massive improvement instead of finding all the free tiles and randomly selecting one. If random selection is a requirement, then functions such as table.insert could be pulled local, as well as caching the size of the table...using # to check size is expensive in traditional lua. I can't really comment on kahlua's handing of # for length checks but I'd assume the cost penalty still applies.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...