Multi-Floor System

Zwiebelchen

You can change this now in User CP.
Reaction score
60
A system that allows 2 coordinate layers instead of just the default one.

Basicly, the system grants you the possibility to create walkable bridges that also allow to walk beneath them.
It could also be used to create two-floor houses for FPS/TPS styled games.

The system provides the following functions:
JASS:
public function GetFloor takes unit u returns integer

The function simply returns the floor-layer the unit is currently at.
0 is the standard terrain layer, 1 is the bridge layer.
JASS:
public function SetFloor takes unit u, integer level returns nothing

Allows to switch between terrain and bridge layer.
This is optional, in case you want to switch layers by using an elevator instead of "ordinary" stairs, where the system does the switching automaticly.

In order to get this system to work, you require the following registry functions:
JASS:
public function RegisterFloorArea takes real minx, real miny, real maxx, real returns nothing

Defines the areas the multi-floors are in.

JASS:
public function RegisterUnitMorphs takes integer unitground, integer unitfly, integer ground2fly, integer fly2ground returns nothing

Registers the unit types to the system that should be able to pass the bridge-layer.
Every registered unit types needs:
- an equivalent flying unit type
- two chaos-based morph abilities, to switch between ground and flying type


Comments & Discussion
The system is not very efficient.
True. However, I wrote this only for testing purposes. Maybe someone has a use for this.

How does it work?
All you need to do, is to use the register functions and place the "Walk Indicator" destructable like you would with an invisible platform. After that add air-pathing blockers to your area and you are done.

My unit doesn't step up the stairs automaticly!
Then maybe the z-offset for the first stair was to high. Either increase the offset setting in the system's constants, or lower the first "Walk Indicator" placed at your stairs.

The unit controls suck and the selection circle is still on the ground ...
Indeed. This is something the flawed engine of warcraft III messes up.
However, this system may still be very useful for those people that use 3rd person styled camera systems and arrow key controls. For this, its perfect.

Units on the ground layer behave weird when they try to pass air-pathing blockers
Yes ... this seems to be another bug in the wc3 engine. Air-pathing blockers suck.


JASS:

library MFS initializer Init

    globals
        private constant integer WalkIndicatorId = 'B001'
        private constant integer FloorChangeMaxOffset = 40
        private constant real HeightChangeVelocity = 1200
        private constant integer DummyId = 'h000'
        private constant player DummyOwner = Player(PLAYER_NEUTRAL_PASSIVE)
        private constant real Update = 0.05
    
    
        private unit dummy = null
        private rect array Rects
        private integer RectCount = 0
        private constant group enum = CreateGroup()
        private constant hashtable FloorHash = InitHashtable()
    endglobals
    
    public function GetFloor takes unit u returns integer
        if u != null then
            return LoadInteger(FloorHash, GetHandleId(u), 0)
        endif
        return 0
    endfunction
    
    public function SetFloor takes unit u, integer level returns nothing
        if u != null then
            call SaveInteger(FloorHash, GetHandleId(u), 0, level)
        endif
    endfunction
    
    public function RegisterFloorArea takes real minx, real miny, real maxx, real maxy returns nothing
        set Rects[RectCount] = Rect(minx, miny, maxx, maxy)
        set RectCount = RectCount+1
    endfunction
    
    public function RegisterUnitMorphs takes integer unitground, integer unitfly, integer ground2fly, integer fly2ground returns nothing
        call SaveInteger(FloorHash, unitground, 0, ground2fly)
        call SaveInteger(FloorHash, unitfly, 0, fly2ground)
    endfunction

    private function GetZ takes real x, real y returns integer
        local location l = null
        local real z = 0
        call SetUnitX(dummy, x)
        call SetUnitY(dummy, y)
        set l = GetUnitLoc(dummy)
        set z = GetLocationZ(l)
        call RemoveLocation(l)
        set l = null
        return R2I(z)
    endfunction
    
    private function RegisterWalkIndicator takes destructable d returns nothing
        local integer x = R2I(GetDestructableX(d))
        local integer y = R2I(GetDestructableY(d))
        local integer tempx = x-32
        local integer tempy = y-32
        local integer z = GetZ(tempx, tempy)
        if LoadInteger(FloorHash, tempx, tempy) < z then
            call SaveInteger(FloorHash, tempx, tempy, z)
        endif
        set tempy = y+32
        set z = GetZ(tempx, tempy)
        if LoadInteger(FloorHash, tempx, tempy) < z then
            call SaveInteger(FloorHash, tempx, tempy, z)
        endif
        set tempx = x+32
        set z = GetZ(tempx, tempy)
        if LoadInteger(FloorHash, tempx, tempy) < z then
            call SaveInteger(FloorHash, tempx, tempy, z)
        endif
        set tempy = y-32
        set z = GetZ(tempx, tempy)
        if LoadInteger(FloorHash, tempx, tempy) < z then
            call SaveInteger(FloorHash, tempx, tempy, z)
        endif
        call RemoveDestructable(d)
    endfunction
    
    private function ModInt takes integer dividend, integer divisor returns integer
        return dividend - (dividend / divisor) * divisor
    endfunction
    
    private function XToGridX takes real x returns integer
        if x < 0 then
            return R2I(x) - ModInt(R2I(x), 64) - 32  
        else
            return R2I(x) - ModInt(R2I(x), 64) + 32
        endif
    endfunction
    
    private function UpdateZ takes nothing returns boolean
        local unit u = GetFilterUnit()
        local integer z = LoadInteger(FloorHash, XToGridX(GetUnitX(u)), XToGridX(GetUnitY(u)))
        if HaveSavedInteger(FloorHash, GetUnitTypeId(u), 0) then //only perform update for registered unit-types
            if GetFloor(u) > 0 then
                if z == 0 then
                    call SetFloor(u, 0)
                    call UnitAddAbility(u, LoadInteger(FloorHash, GetUnitTypeId(u), 0))
                endif
                if R2I(GetUnitFlyHeight(u)) != z then
                    call SetUnitFlyHeight(u, z, HeightChangeVelocity)
                endif
            else
                if z > 0 and z < FloorChangeMaxOffset then
                    call SetFloor(u, 1)
                    call UnitAddAbility(u, LoadInteger(FloorHash, GetUnitTypeId(u), 0))
                    if R2I(GetUnitFlyHeight(u)) != z then
                        call SetUnitFlyHeight(u, z, HeightChangeVelocity)
                    endif
                endif
            endif
        endif
        set u = null
        return false
    endfunction
       
    private function UpdateAllRects takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i >= RectCount
            call GroupEnumUnitsInRect(enum, Rects<i>, Condition(function UpdateZ))
            set i = i + 1
        endloop
    endfunction
    
    private function RegisterAllWalkIndicators takes nothing returns nothing
        local destructable d = GetEnumDestructable()
        if GetDestructableTypeId(d) == WalkIndicatorId then
            call RegisterWalkIndicator(d)
        endif
        set d = null
    endfunction
    
    private function Init takes nothing returns nothing
        local timer t = CreateTimer()
        call TimerStart(t, Update, true, function UpdateAllRects)
        set t = null
        set dummy = CreateUnit(DummyOwner, DummyId, 0, 0, 0)
        call SetUnitPathing(dummy, false)
        call EnumDestructablesInRect(bj_mapInitialPlayableArea, null, function RegisterAllWalkIndicators)
    endfunction
endlibrary</i>
 

Attachments

  • MultiFloorSystem.w3x
    17.3 KB · Views: 313

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Code?

Just took a look in the code. You can make each grid become a struct for it.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
First, how is this possible?
Second, is it possible to have two units at the same spot, on different levels?
And third, please post the code...
 

HydraRancher

Truth begins in lies
Reaction score
197
True. However, I wrote this only for testing purposes. Maybe someone has a use for this.

Daxtreme said:
We want Quality, not Quantity. Thus, submit only what you think is good! If your post contains something like "check out my crappy spell" it will hit graveyard right away.


Also, why dont you use [noparse]
JASS:
[/noparse] tags? It looks much neater that way.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Code?

Just took a look in the code. You can make each grid become a struct for it.
Why? I need an unlimited two-dimensional array here and I only store 1 variable to each grid center, so a hashtable is the most efficient way to do it in this case.

Second, is it possible to have two units at the same spot, on different levels?
That is the whole purpose of this system.

We want quality, not quantity
Okay, maybe you misunderstood me here:
The system itself is pretty effective; however, it has serious flaws in terms of graphic style and unit-mouse controls that I could not fix, as they are hardcoded to the game engine.
However, all of these can be removed by using keyboard controled unit movement instead of mouse control.
 

Azlier

Old World Ghost
Reaction score
461
Units on the second level can walk right through eachother.
 

GooS

Azrael
Reaction score
154
Fun to play around with, but as you say, wc3 can't support it so it becomes .. bad.

Is this something similar to what they used in that FPS map? (Doubt there's more than one)

Anyways, just as that map, its something new and cool and all that, but it breaks in so many ways that it becomes relatively useless.

//==GooS
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
I agree. However, as I already said I wrote this almost only for the reason to find out wether it is generally possible.

I think in SC2, you are able to do far better than that, as the most crucial drawbacks of this are negated in SC2:

1) Shadows will be dynamicly generated by your graphics card in SC2, so they don't look weird on the second layer anymore
2) As SC2 allows changing of unit data directly through triggers, no more "flying unit" change is required and the selection circle remains at your unit correctly
3) SC2 might be able to directly get a destructables or doodads Z value, so no more dummy platforms are required
4) Possibly a better dynamic way of pathing blocking

The only issue that will still suck in terms of multi-floor-ability on SC2 is the fact that you would still have the problem with the mouse ordering of units - but most funmaps on SC2 will have 3rd person view and arrow key controls anyways.:D
 

D.V.D

Make a wish
Reaction score
73
Would this system stop melee units from attacking other units that are above them?
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
As far as i understood Ziebelchen units on the second layer are "flying units" so melee units which cannot attack flying units cannot attack units on the second layer as well.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top