1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-18 02:16:23 -05:00

Fix up subtile flag stuff (#288)

* Switch to a 2d array for looking up subtile flags

Also fix up the walkableArea generation

* Check correct tiletype for walls

And fix the subtile tooltip text.
This commit is contained in:
Ziemas 2020-02-02 23:56:58 +01:00 committed by GitHub
parent 241e8e2875
commit 0b7a433ed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 23 deletions

View File

@ -16,9 +16,15 @@ type Tile struct {
Blocks []Block Blocks []Block
} }
func (t *Tile) GetSubTileFlags(x, y int) *SubTileFlags { var subtileLookup = [5][5]int{
if x < 0 || x > 4 || y < 0 || y > 4 { {20, 21, 22, 23, 24},
return &SubTileFlags{} {15, 16, 17, 18, 19},
} {10, 11, 12, 13, 14},
return &t.SubTileFlags[x + (y * 5)] {5, 6, 7, 8, 9},
{0, 1, 2, 3, 4},
}
func (t *Tile) GetSubTileFlags(x, y int) *SubTileFlags {
return &t.SubTileFlags[subtileLookup[y][x]]
} }

View File

@ -20,9 +20,9 @@ import (
) )
type PathTile struct { type PathTile struct {
Walkable bool Walkable bool
Up, Down, Left, Right, UpLeft, UpRight, DownLeft, DownRight *PathTile Up, Down, Left, Right, UpLeft, UpRight, DownLeft, DownRight *PathTile
X, Y float64 X, Y float64
} }
func (t *PathTile) PathNeighbors() []astar.Pather { func (t *PathTile) PathNeighbors() []astar.Pather {
@ -153,11 +153,11 @@ func loadRegion(seed int64, tileOffsetX, tileOffsetY int, levelType d2enum.Regio
} }
func (mr *MapRegion) generateWalkableMatrix() { func (mr *MapRegion) generateWalkableMatrix() {
mr.walkableArea = make([][]PathTile, mr.tileRect.Height * 5) mr.walkableArea = make([][]PathTile, mr.tileRect.Height*5)
for y := 0; y < mr.tileRect.Height * 5; y++ { for y := 0; y < mr.tileRect.Height*5; y++ {
mr.walkableArea[y] = make([]PathTile, mr.tileRect.Width * 5) mr.walkableArea[y] = make([]PathTile, mr.tileRect.Width*5)
ty := int(float64(y) / 5.0) ty := int(float64(y) / 5.0)
for x := 0; x < mr.tileRect.Width * 5; x++ { for x := 0; x < mr.tileRect.Width*5; x++ {
tx := int(float64(x) / 5.0) tx := int(float64(x) / 5.0)
tile := mr.GetTile(tx, ty) tile := mr.GetTile(tx, ty)
isBlocked := false isBlocked := false
@ -165,7 +165,7 @@ func (mr *MapRegion) generateWalkableMatrix() {
tileData := mr.GetTileData(int32(floor.Style), int32(floor.Sequence), d2enum.Floor) tileData := mr.GetTileData(int32(floor.Style), int32(floor.Sequence), d2enum.Floor)
tileSubAttrs := &d2dt1.SubTileFlags{} tileSubAttrs := &d2dt1.SubTileFlags{}
if tileData != nil { if tileData != nil {
tileSubAttrs = tileData.GetSubTileFlags(x % 5, 4 - (y % 5)) tileSubAttrs = tileData.GetSubTileFlags(x%5, y%5)
} }
isBlocked = isBlocked || tileSubAttrs.BlockWalk isBlocked = isBlocked || tileSubAttrs.BlockWalk
if isBlocked { if isBlocked {
@ -174,12 +174,12 @@ func (mr *MapRegion) generateWalkableMatrix() {
} }
if !isBlocked { if !isBlocked {
for _, wall := range tile.Walls { for _, wall := range tile.Walls {
tileData := mr.GetTileData(int32(wall.Style), int32(wall.Sequence), d2enum.Floor) tileData := mr.GetTileData(int32(wall.Style), int32(wall.Sequence), d2enum.TileType(wall.Type))
tileSubAttrs := &d2dt1.SubTileFlags{} tileSubAttrs := &d2dt1.SubTileFlags{}
if tileData != nil { if tileData != nil {
tileSubAttrs = tileData.GetSubTileFlags(x % 5, 4 - (y % 5)) tileSubAttrs = tileData.GetSubTileFlags(x%5, y%5)
} }
isBlocked = isBlocked || tileSubAttrs.BlockPlayerWalk isBlocked = isBlocked || tileSubAttrs.BlockWalk
if isBlocked { if isBlocked {
break break
} }
@ -187,10 +187,10 @@ func (mr *MapRegion) generateWalkableMatrix() {
} }
mr.walkableArea[y][x] = PathTile{ mr.walkableArea[y][x] = PathTile{
Walkable: !isBlocked, Walkable: !isBlocked,
X: float64(x) / 5.0, X: float64(x) / 5.0,
Y: float64(y) / 5.0, Y: float64(y) / 5.0,
} }
if !isBlocked && y > 0 && mr.walkableArea[y-1][x].Walkable { if !isBlocked && y > 0 && mr.walkableArea[y-1][x].Walkable {
mr.walkableArea[y][x].Up = &mr.walkableArea[y-1][x] mr.walkableArea[y][x].Up = &mr.walkableArea[y-1][x]
mr.walkableArea[y-1][x].Down = &mr.walkableArea[y][x] mr.walkableArea[y-1][x].Down = &mr.walkableArea[y][x]
} }
@ -202,7 +202,7 @@ func (mr *MapRegion) generateWalkableMatrix() {
mr.walkableArea[y][x].UpLeft = &mr.walkableArea[y-1][x-1] mr.walkableArea[y][x].UpLeft = &mr.walkableArea[y-1][x-1]
mr.walkableArea[y-1][x-1].DownRight = &mr.walkableArea[y][x] mr.walkableArea[y-1][x-1].DownRight = &mr.walkableArea[y][x]
} }
if !isBlocked && y > 0 && x < (mr.tileRect.Width * 5) && mr.walkableArea[y-1][x+1].Walkable { if !isBlocked && y > 0 && x < (mr.tileRect.Width*5) && mr.walkableArea[y-1][x+1].Walkable {
mr.walkableArea[y][x].UpRight = &mr.walkableArea[y-1][x+1] mr.walkableArea[y][x].UpRight = &mr.walkableArea[y-1][x+1]
mr.walkableArea[y-1][x+1].DownLeft = &mr.walkableArea[y][x] mr.walkableArea[y-1][x+1].DownLeft = &mr.walkableArea[y][x]
} }
@ -474,7 +474,7 @@ func (mr *MapRegion) renderWall(tile d2ds1.WallRecord, viewport *Viewport, targe
return return
} }
viewport.PushTranslationOrtho(-80, float64(tile.YAdjust) - 16) viewport.PushTranslationOrtho(-80, float64(tile.YAdjust)-16)
defer viewport.PopTranslation() defer viewport.PopTranslation()
target.PushTranslation(viewport.GetTranslationScreen()) target.PushTranslation(viewport.GetTranslationScreen())
@ -521,7 +521,7 @@ func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *View
} }
subTileColor := color.RGBA{R: 80, G: 80, B: 255, A: 50} subTileColor := color.RGBA{R: 80, G: 80, B: 255, A: 50}
tileColor := color.RGBA{R: 255, G: 255, B: 255, A: 100} tileColor := color.RGBA{R: 255, G: 255, B: 255, A: 100}
tileCollisionColor := color.RGBA{R: 128, G:0, B:0, A:100} tileCollisionColor := color.RGBA{R: 128, G: 0, B: 0, A: 100}
screenX1, screenY1 := viewport.WorldToScreen(float64(x), float64(y)) screenX1, screenY1 := viewport.WorldToScreen(float64(x), float64(y))
screenX2, screenY2 := viewport.WorldToScreen(float64(x+1), float64(y)) screenX2, screenY2 := viewport.WorldToScreen(float64(x+1), float64(y))
@ -551,6 +551,7 @@ func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *View
} }
tile := mr.ds1.Tiles[ay][ax] tile := mr.ds1.Tiles[ay][ax]
for i, floor := range tile.Floors { for i, floor := range tile.Floors {
target.PushTranslation(-20, 10+(i+1)*14) target.PushTranslation(-20, 10+(i+1)*14)
target.DrawText("f: %v-%v", floor.Style, floor.Sequence) target.DrawText("f: %v-%v", floor.Style, floor.Sequence)
@ -562,7 +563,7 @@ func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *View
isoX := (xx - yy) * 16 isoX := (xx - yy) * 16
isoY := (xx + yy) * 8 isoY := (xx + yy) * 8
target.PushTranslation(isoX-3, isoY+4) target.PushTranslation(isoX-3, isoY+4)
var walkableArea = mr.walkableArea[yy + (ay * 5)][xx + (ax * 5)] var walkableArea = mr.walkableArea[yy+(ay*5)][xx+(ax*5)]
if !walkableArea.Walkable { if !walkableArea.Walkable {
target.DrawRect(5, 5, tileCollisionColor) target.DrawRect(5, 5, tileCollisionColor)
} }

View File

@ -191,8 +191,9 @@ func (met *MapEngineTest) Render(screen d2render.Surface) {
tileX := int(math.Floor(worldX)) - tileRect.Left tileX := int(math.Floor(worldX)) - tileRect.Left
tileY := int(math.Floor(worldY)) - tileRect.Top tileY := int(math.Floor(worldY)) - tileRect.Top
subtileX := int((worldX - float64(int(worldX))) * 5) subtileX := int((worldX - float64(int(worldX))) * 5)
subtileY := 4 - int((worldY-float64(int(worldY)))*5) subtileY := int((worldY - float64(int(worldY))) * 5)
regionWidth, regionHeight := curRegion.GetTileSize() regionWidth, regionHeight := curRegion.GetTileSize()
if tileX >= 0 && tileY >= 0 && tileX < regionWidth && tileY < regionHeight { if tileX >= 0 && tileY >= 0 && tileX < regionWidth && tileY < regionHeight {