Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

sight.gno

0.92 Kb · 25 lines
 1package engine
 2
 3import "gno.land/p/g1th0masp67zfs9lg6d34qhghldhg6kjcqjuv7c2/gnoslinger/hex/v0"
 4
 5// sightHeight is a character's height for the line of sight (30.32):
 6// upright, or DOWN unless it lies on an obstacle, where it counts as
 7// upright.
 8func sightHeight(board *hex.Board, c *Character) hex.Height {
 9	if c.Down && !board.Obstacle(c.Hex) {
10		return hex.HeightDown
11	}
12	return hex.HeightUpright
13}
14
15// canSee reports whether c has a clear line of sight (rule 31) to its
16// target: the character t when t is not nil, wherever it stands and at its
17// height, else the hex at, which counts as upright (31.3). blocker names
18// the obstacle in the way. The aim zone is checked apart (31.21).
19func canSee(board *hex.Board, c *Character, at string, t *Character) (clear bool, blocker string) {
20	h := hex.HeightUpright
21	if t != nil {
22		at, h = t.Hex, sightHeight(board, t)
23	}
24	return board.LineOfSight(c.Hex, at, sightHeight(board, c), h)
25}