How to make unit avoid snow?

staind25

TH.net Regular
Reaction score
7
I have a custom unit based off of a Footman that I want to avoid specific tiles. The reason being, I have a path drawn for it, and when I order it to "attack-move", I want it to follow that path. It would really cut down on the triggering (Map is large and the unit's going across the map).

Is this possible? If so, how do I go about doing this?

My idea was to somehow use the object editor, and a little triggering if necessary. I was thinking of checking "Editor - Has Tileset Specific Data", but from there, I'm not sure how to specify that I want snow to be unwalkable for that unit.

Thank you :)
 

Sui-cookie

You can change this now in User CP.
Reaction score
49
wellll you could always edit tile path ability for snow to be un-walkable, but then no units except flying could go on them... and idk if footmen are the only units in your map?

nvm, i didnt read:
I'm not sure how to specify that I want snow to be unwalkable for that unit.

umm. idk , ill see if i can figure something out o_O
 

xPass

All aboard the xPass Express!
Reaction score
26
What about using regions to move, though it WILL flood the WE with triggers :D (Or do you not want a lot of triggers?)
 

HydraRancher

Truth begins in lies
Reaction score
197
What about using regions to move, though it WILL flood the WE with triggers :D (Or do you not want a lot of triggers?)

You can use 2 triggers to make it walk along a path.

I don't think it's possible to create a path that is unpathable for 1 unit type. You'll have to use triggers & regions.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
My idea was to somehow use the object editor, and a little triggering if necessary. I was thinking of checking "Editor - Has Tileset Specific Data", but from there, I'm not sure how to specify that I want snow to be unwalkable for that unit.

No, tileset specific data means that it only appears on the list of neutral units for a certain tileset. You could make a periodic trigger to check if the terrain under the footman is snow, and if so move it back a small range.
 

staind25

TH.net Regular
Reaction score
7
Thanks for the responses...sorry it took me awhile to get back.

@HydraRancher, which 2 triggers are you referring to? If I could order a unit to walk along a specified path with only 2 triggers across the whole map I'd be very happy.

@Sui-cookie, yeah, I'm trying to make it so that it only affects this unit, not the whole game :)

@xPass, using a ton of triggers is the most likely option but also my last resort. It would take a LOT of triggers and a ton of regions too. The map is already very large and has tons of regions/triggers...I'd be concerned with lag after all of that.

@KaerfNomekop, ahh, thanks for the clarification. I was actually thinking about a solution such as that. I was thinking maybe something like:

Every x seconds...
set TempPoint = point 100 range in front of unit
if terrain at TempPoint = snow, then make that square unwalkable
wait (some small interval)
make that square walkable again

I'm HOPING that this would make it so that the unit would have to seek an alternate path, assuming the game would figure out that it's unwalkable a short time in advance. Not sure if this is possible but was thinking about it. Think I'll give it a shot, seeing as there's apparently no easy way to do it, haha.

Thank you all, again. Much appreciated.
 

Hatebreeder

So many apples
Reaction score
381
JASS:
function IsTerrainSnow takes unit u, real a  returns real
     local real UnitX = GetUnitX(u)
     local real UnitY = GetUnitY(u)
     local real X
     local real Y
     local integer Addition = 0

     loop
      set X = UnitX + DISTANCE * Cos((a*bj_RADTODEG)+addition)
      set Y = UnitY + DISTANCE * Sin((a*bj_RADTODEG)+addition)
         exitwhen IsTerrainType(X,Y) != 'SNOW' or Addition >= 360
      set Addition = Addition + 1
    endloop

    set a = ((a*bj_RADTODEGG) + Addition) * bj_DEGTORAD
    return a
endfunction


JASS:
function Move takes nothing returns nothing
   local unit Ordered = GetEnumUnit()
   local real Angle = IsTerrainSnow(Ordered,GetUnitFacing(Ordered))
   local real X = GetUnitX(Ordered) + DISTANCE * Cos(Angle)
   local real Y = GetUnitY(Ordered) + DISTANCE * Sin(Angle)

   call IssuePointOrder(Ordered,"attack",X,Y)
   set Ordered = null
endfunction


JASS:
function Timer takes nothing returns nothing
    local timer Timer = GetExpiredTimer()
    
    call ForGroup( UNITGROUP, function Move )

    set Timer = null
endfunction


"DISTANCE" is a global real (can also be a function) that defines the range of the path the unit should move.
"UNITGROUP" is a global group that contains all the units you want to move.
Just make a function that adds all units that enter the map of a type and initiate the Timer function during Map init or 0.00 of game time.

PS: I just freehanded this one, so you'd need to correct one or two things. But the structure of it should be right.
 

staind25

TH.net Regular
Reaction score
7
Wow, very nice. I don't know my JASS, but I should be able to understand this...just not be able to write my own. Thank you very much. Going to take a detailed look here in a minute.

Edit: Due to lack of experience, I'm not exactly sure how to integrate this. Do each of those functions go in their own triggers, or do they all go in one? Also, what purpose does the timer serve? Guess I'm not sure why a timer is needed.

For the globals, how do I define DISTANCE? I should be able to handle UNITGROUP but not sure how and what value to give DISTANCE.

Thanks again :)
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Distance is real value.

hatebreeder said:
"DISTANCE" is a global real (can also be a function) that defines the range of the path the unit should move.

He already said that :p
 

staind25

TH.net Regular
Reaction score
7
I know, but I'm asking what value I should give it. Like...how do I determine the value?
 

Hatebreeder

So many apples
Reaction score
381
I know, but I'm asking what value I should give it. Like...how do I determine the value?

I usually take 20-40 for missiles.

Since units are not that fast usually, try something like 17 =P

EDIT:
JASS:
library WhiteOut initializer Init
// Create a new trigger. Rename it to "WhiteOut" and convert it to Text.
// Replace the Text with this.
// Check the Rawcodes in the object editor using CTRL + D

   globals
      private constant integer TERRAIN = 'SNOW'
      private constant real DISTANCE = 17.00

      private group UNITGROUP = CreateGroup()
   endglobals

private function IsTerrainSnow takes unit u, real a  returns real
     local real UnitX = GetUnitX(u)
     local real UnitY = GetUnitY(u)
     local real X
     local real Y
     local integer Addition = 0

     loop
      set X = UnitX + DISTANCE * Cos((a*bj_RADTODEG)+Addition)
      set Y = UnitY + DISTANCE * Sin((a*bj_RADTODEG)+Addition)
         exitwhen GetTerrainType(X,Y) != TERRAIN or Addition >= 360
      set Addition = Addition + 1
    endloop

    set a = ((a*bj_RADTODEG) + Addition) * bj_DEGTORAD
    return a
endfunction

private function Move takes nothing returns nothing
   local unit Ordered = GetEnumUnit()
   local real Angle = IsTerrainSnow(Ordered,GetUnitFacing(Ordered))
   local real X = GetUnitX(Ordered) + DISTANCE * Cos(Angle)
   local real Y = GetUnitY(Ordered) + DISTANCE * Sin(Angle)

   call IssuePointOrder(Ordered,"attack",X,Y)
   set Ordered = null
endfunction

private function Timer takes nothing returns nothing
    local timer Timer = GetExpiredTimer()
    
    call ForGroup( UNITGROUP, function Move )

    set Timer = null
endfunction

private function Truth takes nothing returns boolean
   return true // Don't bother with this. It's only there to prevent a leak.
endfunction

private function Conditions takes nothing returns boolean
   return true //replace the Conditions with the units you want to effect
endfunction

private function Actions takes nothing returns nothing
   call GroupAddUnit(UNITGROUP,GetEnteringUnit())
endfunction

private function Init takes nothing returns nothing
   local trigger Trig = CreateTrigger()
   local timer Time = CreateTimer()
   local rect r = CreateRegion()   

   call RegionAddRect(r, bj_mapInitialPlayableArea)
   call TriggerRegisterEnterRegion(Trig , r, function Truth)
   call TriggerAddCondition( Trig, Condition( function Conditions))
   call TriggerAddAction( Trig, function Actions)

   call TimerStart(Time,0.03,true,function Timer)

   call RemoveRegion(r)

   set Time = null
   set Trig = null
   set r = null
endfunction
endlibrary


I went ahead and summed it up into a library and gave you import instructions. Now, you just need to replace the values I commented on and the globals.
It's not perfect, but I guess this will do.

I also have corrected the mistakes in my freehanded one, so, this should be fine.
If not, gimme a PM with the error message and I'll fix it.

You need Jass New Gen for this to work.
 

Switch33

New Member
Reaction score
12
Pretty sure UMSWE found in newgen can do this completely for you if you edit the tilesets pathability.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top