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: 326

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,463
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 The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top