• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Creating unit out of bounds / unwalkable terrain

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

So apparently if a unit is created at location which is outside the map bounds, it crashes?

Or is the proper term that the thread where it came from crashes? I've got a trigger that picks a random point around a unit and creates a unit at the point (random point on a circle). Never once did my game crash...I would have expected at some point a unit would be attempted to be created out of bounds.

So if it's being done its own thread, is it even necessary to check world bounds on the point? If it crashes the thread, then it crashes. Or would it leak a unit reference?

I've got WorldBounds library though, so I suppose I should add that in as an additional check when generating a random location?

Second part of the question: What about creating a unit on terrain that isn't walkable, e.g. a land unit being spawned on a location in the water, or in a boundary area (that's still inside the world bounds).

What happens in that case? Does the unit instance still exist? Does it crash the thread, or will code continue to execute?

JASS:
local unit u = CreateUnitAtLoc('Hpal', ..., waterLoc, ...)
//what happens now?  what does u point to? 
//will the following code run properly?
call SetHeroLevel(u, 100, true) 
//will I see the unit level up at the waterLoc?
call SetUnitLoc(u, myLoc) 
//will the unit appear suddenly at this loc?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
If you have WorldBounds library you don't need to worry about first case.In case you wondering, I heard when a unit outside bounds ordered to do something, it crashes game(fatal error).Not sure if it is still exist.

Second case, everything will be fine.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
What happens in the second case, though? And how does putting in WorldBounds fix everything automatically? I'm using Nestharus' worldbounds, as shown below.

JASS:
library_once WorldBounds /* v2.0.0.0
************************************************************************************
*
*   struct WorldBounds extends array
*       readonly static integer maxX
*       readonly static integer maxY
*       readonly static integer minX
*       readonly static integer minY
*       readonly static integer centerX
*       readonly static integer centerY
*       readonly static rect world
*       readonly static region worldRegion
*
************************************************************************************/
    
    private module WorldBoundInit
        private static method onInit takes nothing returns nothing
            set world=GetWorldBounds()
            set maxX=R2I(GetRectMaxX(world))
            set maxY=R2I(GetRectMaxY(world))
            set minX=R2I(GetRectMinX(world))
            set minY=R2I(GetRectMinY(world))
            set centerX=R2I((maxX+minX)/2)
            set centerY=R2I((minY+maxY)/2)
            set worldRegion=CreateRegion()
            call RegionAddRect(worldRegion,world)
        endmethod
    endmodule
    struct WorldBounds extends array
        readonly static integer maxX
        readonly static integer maxY
        readonly static integer minX
        readonly static integer minY
        readonly static integer centerX
        readonly static integer centerY
        readonly static rect world
        readonly static region worldRegion
        implement WorldBoundInit
    endstruct
endlibrary
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
The second case, units will be created perfectly. I've tried making water in start locs. xD

They won't move tho if Land walkers.

If they are land based units, and they are created in a location which is

1. water

What happens? Do they get spawned? ???

2. boundary (not out of bounds though, just the black boundary terrain).

Same thing--what happens???
 
Status
Not open for further replies.
Top