diff --git a/TODO b/TODO index 0896bbc..0ba2c21 100644 --- a/TODO +++ b/TODO @@ -20,5 +20,4 @@ Bugs: - Cannot move from magic wood tree to dark citadel - Players can attack walls? - Magic wood, make it gift players with a spell sometimes if they are mounted. - - Make magic wood casting be line of sight - Line of sight calculation seems a bit harsh currently diff --git a/grid/grid.go b/grid/grid.go index 74e8de2..71d0565 100644 --- a/grid/grid.go +++ b/grid/grid.go @@ -88,3 +88,12 @@ func (grid *GameGrid) AnimationTick(odd bool) { func (grid *GameGrid) AsRect() logical.Rect { return logical.R(grid.MaxX(), grid.MaxY()) } + +func (grid *GameGrid) HaveLineOfSight(from, to logical.Vec) bool { + for _, pathV := range to.Subtract(from).Path() { + if !grid.GetGameObject(from.Add(pathV)).IsEmpty() { + return false + } + } + return true +} diff --git a/screen/attack.go b/screen/attack.go index 46de8bb..281270d 100644 --- a/screen/attack.go +++ b/screen/attack.go @@ -69,7 +69,7 @@ func (screen *RangedCombat) Step(ctx screeniface.GameCtx) screeniface.GameScreen textBottom("Out of range", ss, batch) screen.OutOfRange = true } else { - if !HaveLineOfSight(characterLocation, attackPosition, grid) { + if !grid.HaveLineOfSight(characterLocation, attackPosition) { textBottom("No line of sight", ss, batch) screen.OutOfRange = true } else { diff --git a/screen/castspell.go b/screen/castspell.go index 1ae2092..874faac 100644 --- a/screen/castspell.go +++ b/screen/castspell.go @@ -114,7 +114,7 @@ func (screen *TargetSpellScreen) Step(ctx screeniface.GameCtx) screeniface.GameS fmt.Printf("Out of range! Spell cast range %d but distance to target is %d\n", spell.GetCastRange(), target.Distance(thisPlayer.BoardPosition)) screen.MessageShown = true } else { - if spell.NeedsLineOfSight() && !HaveLineOfSight(thisPlayer.BoardPosition, target, grid) { + if spell.NeedsLineOfSight() && !grid.HaveLineOfSight(thisPlayer.BoardPosition, target) { textBottom("No line of sight", ss, batch) screen.MessageShown = true } else { diff --git a/screen/utils.go b/screen/utils.go index fef49fc..d3bcae5 100644 --- a/screen/utils.go +++ b/screen/utils.go @@ -67,15 +67,6 @@ func WeHaveAWinner(players []*player.Player) bool { return c == 1 } -func HaveLineOfSight(from, to logical.Vec, grid *grid.GameGrid) bool { - for _, pathV := range to.Subtract(from).Path() { - if !grid.GetGameObject(from.Add(pathV)).IsEmpty() { - return false - } - } - return true -} - var numKeyMap map[pixelgl.Button]int var spellKeyMap map[pixelgl.Button]int var directionKeyMap map[pixelgl.Button]logical.Vec diff --git a/spellswithscreen/magic_wood.go b/spellswithscreen/magic_wood.go index 3c3fbc4..14d07c7 100644 --- a/spellswithscreen/magic_wood.go +++ b/spellswithscreen/magic_wood.go @@ -87,7 +87,9 @@ func getMagicWoodTiles(ctx screeniface.GameCtx, playerIdx int) []logical.Vec { if !grid.GetGameObject(possibleVec).IsEmpty() { continue } - // FIXME - adjacent to the player is OK + if !grid.HaveLineOfSight(fromPosition, possibleVec) { + continue + } if adjacentsAreNotMagicWood(ctx, possibleVec) { //fmt.Printf("Add possible Vec X%d Y%d\n", possibleVec.X, possibleVec.Y) maybeTiles = append(maybeTiles, possibleVec)