• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Boardgame Geometrical issue - Still not getting it!

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Heya!

I'm still not really getting it how I should add a function to the turn-based Board Game I'm making. It's a very geometrical issue I suppose.

I've got a board game playfield in the map. I indexed it (a littlebit funky) but it looks like the picture I added as an attachment. The fields inside with '...' are part of the playfield. The black parts aren't.
Currently I'm already too far to re-index the gamefield to, per example, flip the y so that it actually goes upwards. However... This shouldn't matter much for the outcome of this code.

The thing I'm having issues with is creating movement on the board while checking pathability after every step. I created something that marks the squares as 'pathable' around the unit based on his range. So let's say he can make 2 steps, the 4+8 squares around him will lighten up. However, if an enemy unit is standing in the way, I so far only could mark that single square as unpathable instead of the ones behind it aswell.
To make sure you get me I added 2 example pictures.
One of them shows the result of what I've got right now.
The other one shows what I really want.
(Yellow area is the unit that's going to move. Green areas are fields that are pathable. Red Areas are fields that are not pathable. The brown one's are out of range.)


So far some people have tried to help me, but they've shortly told me what to do and I barely understood what they were talking about. I was wondering if there's anyone that would like to make this for me, or patiently help me while I give it another shot.


Here's what I got right now (the code with the wrong result):
JASS:
local integer X = Unit_X[GetUnitId(u)] ///This is the Field X value of the unit. It's something between 1 and 9
local integer Y = Unit_Y[GetUnitId(u)] ///This is the Field Y value of the unit. It's something between 0 and 17
local integer x = 0
local integer y = 0
local integer STEPS = RANGE ///So if the unit can max. move 2 steps this will be set to 2

    loop
    exitwhen x > RANGE
        loop
        exitwhen y > (RANGE - x)
            if Field_Path[X+x][Y+y] == 0 then ///Field_Path checks how many units are on the selected field. 0 means its pathable unitwise
                if IsRegAbleToMove(u, X+x, Y+y) then ///This one is not important now. (Checks if the field is water or cliff and checks if moving unit can climb or swim)
                    set Field_Pathable[X+x][Y+y] = true ///This turns the field to green
                endif
            endif
            if Field_Path[X-x][Y+y] == 0 then
                if IsRegAbleToMove(u, X-x, Y+y) then
                    set Field_Pathable[X-x][Y+y] = true
                endif
            endif
            if Field_Path[X+x][Y-y] == 0 then
                if IsRegAbleToMove(u, X+x, Y-y) then
                    set Field_Pathable[X+x][Y-y] = true
                endif
            endif
            if Field_Path[X-x][Y-y] == 0 then
                if IsRegAbleToMove(u, X-x, Y-y) then
                    set Field_Pathable[X-x][Y-y] = true
                endif
            endif
            
            set y = y +1
            set STEPS = STEPS - 1
        endloop
        set STEPS = RANGE - x
        set y = 0
        set x = x + 1
        set STEPS = STEPS - 1
    endloop

PS:
I was planning to start all over on this part of the code. So don't feel as if I want to keep what I got right now and edit it.
I think I have to go with a new approach anyway.
 

Attachments

  • Game Field.jpg
    Game Field.jpg
    41.6 KB · Views: 111
  • What I have.jpg
    What I have.jpg
    116.2 KB · Views: 108
  • What I want.jpg
    What I want.jpg
    115.9 KB · Views: 95
Level 25
Joined
Jul 10, 2006
Messages
3,315
Some pseudocode:
Code:
function GetAdjacentBlocks takes unit u, integer range
  //get coordinates of u
  for integer i from 1 to 4 //we're checking the 4 adjacent blocks, so we're looping with a 90 degree step
    set tempRange = range
    set point = unitPosition offset by 128 towards 90 * i
    if (point is pathable) //using your current algorithm
    then
      //mark the point as pathable
      if (tempRange > 1)
      then
        set tempRange = tempRange - 1
        call GetAdjacentBlocks(u, tempRange) //we're using this same function to check blocks in range of this new block
      else - nothing
    else - nothing

This is a recursive function (google it).

How it works:
Say we have a unit with 3 range. On the first call, it checks the first adjacent block, the one above the unit. This block happens to be occupied by another unit, as is unpathable, so we continue to check the block to the left of the unit.
This block is pathable, so now we check the unit's range, which is 3, which means that after the unit reaches this block, it can move again. So now we call this same function again with this new block as the point, but this time with 1 less range. So this new instance of the function checks all point adjacent to this point, and so on.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Some pseudocode:
Code:
function GetAdjacentBlocks takes unit u, integer range
  //get coordinates of u
  for integer i from 1 to 4 //we're checking the 4 adjacent blocks, so we're looping with a 90 degree step
    set tempRange = range
    set point = unitPosition offset by 128 towards 90 * i
    if (point is pathable) //using your current algorithm
    then
      //mark the point as pathable
      if (tempRange > 1)
      then
        set tempRange = tempRange - 1
        call GetAdjacentBlocks(u, tempRange) //we're using this same function to check blocks in range of this new block
      else - nothing
    else - nothing

This is a recursive function (google it).

How it works:
Say we have a unit with 3 range. On the first call, it checks the first adjacent block, the one above the unit. This block happens to be occupied by another unit, as is unpathable, so we continue to check the block to the left of the unit.
This block is pathable, so now we check the unit's range, which is 3, which means that after the unit reaches this block, it can move again. So now we call this same function again with this new block as the point, but this time with 1 less range. So this new instance of the function checks all point adjacent to this point, and so on.

Ah I see!
Never thought of that.
Going to fool around with it.
Thanks alot!
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Can't really get it to work.
This is what I came up with. Guess I'm stuck for now since I should get some sleep. Gonna try more tomorrow but it's giving weird results right now however it should be fine while I'm looking at the code.

JASS:
function AddMovementColors takes unit u, integer X, integer Y, integer Range, boolean UnitWalk returns nothing
    local player p = GetOwningPlayer(u)
    local integer Steps = Range
    local integer i = 0
    local integer x = 0
    local integer y = 0
    
    if UnitWalk then
    
    else
        loop
            exitwhen i > 3
            if i == 0 then
                set x = 1
                set y = 0
            elseif i == 1 then
                set x = -1
                set y = 0
            elseif i == 2 then
                set x = 0
                set y = 1
            else
                set x = 0
                set y = -1
            endif
            if Field_Path[X+x][Y+y] == 0 and Field[X+x][Y+y] != null and IsRegAbleToMove(u, X+x, Y+y) then
                set Field_Pathable[X+x][Y+y] = true
                if GetLocalPlayer() == p then
                    call ShowDestructable(Tile_Red[X+x][Y+y], false)
                    call ShowDestructable(Tile_Green[X+x][Y+y], true)
                endif
                set Field_Pathable[X+x][Y+y] = true
                if Steps > 1 then
                    set Steps = Steps - 1
                    call AddMovementColors(u, X+x, Y+y, Steps, UnitWalk)
                endif
            endif
            set i = i + 1
        endloop
    endif
    
    set p = null
    set u = null
endfunction
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Awesome!

Upload a new video soon :)

Will do tomorrow.
Got some time then.
Currently started working on an interface that shows you which cards are in your deck and allows players to add and remove items to stash.
Just have to read up about hashtables cus I suck with them.
I might show something about it tomorrow.:D
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Arrays are more than enough to make this.

I made a similar map many years ago, custom deckbuilding was basically just a whole bunch of card shops, whenever a card was bought, it was set to the next empty spot;
P1CardId = p1CardId + 1
Player1Cards[P1CardId] = sold item
(it's only two players, so make a set of triggers for each player)

For display you could just do a multiboard, every time it updates it would loop through all cards in the list and display each one in a new cell in the board.
For removal, you could make a command -remove X, which would remove Player1Cards[X], and move all cards beyond it down one slot.
 
Status
Not open for further replies.
Top