Version: v0.2.21 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 10 Imported by: 0




View Source
const API_BASE = "https://calamityofsubterfuge.com"

API_BASE contains the base URL of the server instance.

View Source
const MAP_HEX_RADIUS = 10.0

MAP_HEX_RADIUS is the radius of each of the hexes on the map which correspond to the player bases in world units. One world unit is 64 pixels at standard zoom.

View Source

MAP_HEX_WALL_THICKNESS is the thickness of the walls on the edge of the map hexes.

View Source
const VISION_DISTANCE = 10.0

VISION_DISTANCE describes the view distance of players. Note that view distance is not calculated as a circle - it is a square where VISION_DISTANCE is half the length of each side. This improves performance and better matches the rectangular nature of clients.

View Source
const WEBSOCKET_ORIGIN = "https://calamityofsubterfuge.com"

WEBSOCKET_ORIGIN is the value of the Origin header on websockets. This is required or the server will reject the websocket, although it's mainly to protect against browsers starting websockets on different websites.


View Source
var CONN_READ_TIMEOUT = 20 * time.Second

CONN_READ_TIMEOUT is the amount of time we spend waiting for a read on the socket before we close the socket.

View Source
var CONN_WRITE_TIMEOUT = 20 * time.Second

CONN_WRITE_TIMEOUT is the amount of time we can spend waiting for a write to be acknowledged on the socket before we close the socket.

View Source
var MapHexCenters = []cp.Vector{
	{X: math.Sqrt(3) * MAP_HEX_RADIUS * math.Cos(math.Pi/6.0), Y: math.Sqrt(3) * MAP_HEX_RADIUS * math.Sin(math.Pi/6.0)},
	{X: math.Sqrt(3) * MAP_HEX_RADIUS * math.Cos(math.Pi/2.0), Y: math.Sqrt(3) * MAP_HEX_RADIUS * math.Sin(math.Pi/2.0)},
	{X: math.Sqrt(3) * MAP_HEX_RADIUS * math.Cos(5*math.Pi/6.0), Y: math.Sqrt(3) * MAP_HEX_RADIUS * math.Sin(5*math.Pi/6.0)},
	{X: math.Sqrt(3) * MAP_HEX_RADIUS * math.Cos(7*math.Pi/6.0), Y: math.Sqrt(3) * MAP_HEX_RADIUS * math.Sin(7*math.Pi/6.0)},
	{X: math.Sqrt(3) * MAP_HEX_RADIUS * math.Cos(3*math.Pi/2.0), Y: math.Sqrt(3) * MAP_HEX_RADIUS * math.Sin(3*math.Pi/2.0)},
	{X: math.Sqrt(3) * MAP_HEX_RADIUS * math.Cos(11*math.Pi/6.0), Y: math.Sqrt(3) * MAP_HEX_RADIUS * math.Sin(11*math.Pi/6.0)},

MapHexCenters maps from the hex index to the center of the hex.

View Source
var MapHexEdgeTriangularization = NewHexEdgeTriangularization(MAP_HEX_RADIUS)

MapHexEdgeTriangularization triangularizes the edges of one map hex. Note that this includes the walls within the hexagon! Use MapHexInnerEdgeTriangularization for just the non-wall part of a map-hex

View Source
var MapHexInnerEdgeTriangularization = NewHexEdgeTriangularization(MAP_HEX_RADIUS - MAP_HEX_WALL_THICKNESS*0.5)

MapHexEdgeTriangularization triangularizes the edges of one map hex, excluding the walls

View Source
var MapHexInnerTriangularization = NewHexTriangularization(MAP_HEX_RADIUS - MAP_HEX_WALL_THICKNESS*0.5)

MapHexInnerTriangularization triangularizes the inner, non-wall part of a hex. Note the center hex has no walls.

View Source
var MapHexTriangularization = NewHexTriangularization(MAP_HEX_RADIUS)

MapHexTriangularization triangularizes one map hex. Note that this includes the wall within the hexagon! Use MapHexInnerTriangularization for just the non-wall part of a map hex


func BodyBodyDistanceSq added in v0.2.5

func BodyBodyDistanceSq(a *cp.Body, b *cp.Body) float64

BodyBodyDistanceSq approximates the squared distance between the two bodies. This is stable but may be an overestimate of the squared distance.

func DecodeHook added in v0.2.14

func DecodeHook(from reflect.Value, to reflect.Value) (interface{}, error)

DecodeHook is a valid mapstructure DecodeHook in order to correctly interpret json.Number, which is a subtype of string, as actual numbers in the target struct. This produces the correct error based on the target size (e.g., the json number 256 can't be stored in a int8, so an error would be produced)

func DecodeWithType added in v0.2.14

func DecodeWithType(parsed map[string]interface{}, typ interface{}) (interface{}, error)

DecodeWithType is a convenience method to use a mapstructure Decoder using the DecodeHook to decode the given map with the given target type.

func RoleToName

func RoleToName(role Role) string

RoleToName converts a role constant to its typical name.

func TimeFromUnix

func TimeFromUnix(t float64) time.Time

TimeFromUnix is a convenience function for converting the unix time returned from API responses into an actual golang time


type Role

type Role int

Role is an enum describing all the roles within the game that players can have. Each player has uniquely one role.

const (
	// RoleInvalid is the default value meaning that there was a bug
	// that caused the player to not have a role set.
	RoleInvalid Role = 0

	// RolePlayer is the role of humans
	RolePlayer Role = 1

	// RoleEconomyAI is the role of AI's acting in a pair to control the
	// fiscal policy of the team
	RoleEconomyAI Role = 2

	// RoleMilitaryAI is the role of AI's acting in a pair to control the
	// defense and foreign policy of the team
	RoleMilitaryAI Role = 3

	// RoleScienceAI is the role of AI's acting in a pair to control the
	// scientific policy of the team
	RoleScienceAI Role = 4

func RoleFromName

func RoleFromName(role string) Role

func (Role) Name

func (r Role) Name() string

Name is an alternative way to call RoleToName

type Triangle added in v0.1.1

type Triangle struct {
	// Vertices are the vertices of the 2d simplex; they must not
	// fall on a line
	Vertices [3]cp.Vector

	// Basis is a 2x2 matrix that makes up the basis for this triangle.
	// If V is a 2x1 vector such that both components are in the unit
	// interval, then BV is a point within the triangle. This can be used
	// to sample from the triangle quickly.
	// the first row is Basis[0], Basis[1]. The second row is Basis[2] Basis[3]
	Basis [4]float64

Triangle describes a 2d simplex

func NewTriangle added in v0.1.1

func NewTriangle(a, b, c cp.Vector) *Triangle

NewTriangle computes the basis of the given triangle then constructs it

func (*Triangle) Area added in v0.1.1

func (t *Triangle) Area() float64

Area computes the area of this triangle.

func (*Triangle) Contains added in v0.1.1

func (t *Triangle) Contains(v cp.Vector) bool

Contains checks if the vector v is in this triangle. This is not the primary intended use of triangles within this package right now and is not optimized

func (*Triangle) Sample added in v0.1.1

func (t *Triangle) Sample() cp.Vector

Sample returns a random vector in this triangle

type Triangularization added in v0.1.1

type Triangularization struct {
	// Triangles contains the triangles within this triangularization.
	// In general this should sorted according to descending area for
	// best performance, but this is not required
	Triangles []Triangle

	// AreaPartialSums contains the sum of the area of all triangles up
	// to and including the index.
	AreaPartialSums []float64

Triangularization is a triangularization of some polygon which can rapidly sampled from

func NewHexEdgeTriangularization added in v0.1.1

func NewHexEdgeTriangularization(radius float64) *Triangularization

NewHexEdgeTriangularization triangularizes a hexagon of the given radius, but without the inner diamond

func NewHexTriangularization added in v0.1.1

func NewHexTriangularization(radius float64) *Triangularization

NewHexTriangularization triangularizes a hexagon of the given radius

func NewTriangularization added in v0.1.1

func NewTriangularization(triangles []Triangle) *Triangularization

NewTriangularization returns a new triangularization produced by the given triangles. The resulting triangularization is a copy of the given slice sorted according to descending area, with area partial sums filled in.

func (*Triangularization) Sample added in v0.1.1

func (t *Triangularization) Sample() cp.Vector

Sample a point uniformly from one of the triangles in this triangularization

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL