2020-07-10 18:39:33 +01:00
|
|
|
package atlas
|
2020-06-26 19:45:24 +01:00
|
|
|
|
2020-07-19 11:50:19 +01:00
|
|
|
import "log"
|
|
|
|
|
2020-07-19 11:47:19 +01:00
|
|
|
// ObjectType represents an object type
|
|
|
|
type ObjectType byte
|
2020-07-03 17:00:04 +01:00
|
|
|
|
|
|
|
// Types of objects
|
2020-06-26 19:45:24 +01:00
|
|
|
const (
|
2020-07-10 18:39:33 +01:00
|
|
|
// ObjectNone represents no object at all
|
2020-07-19 11:47:19 +01:00
|
|
|
ObjectNone = ObjectType(GlyphNone)
|
2020-06-30 23:59:58 +01:00
|
|
|
|
2020-07-10 18:39:33 +01:00
|
|
|
// ObjectRover represents a live rover
|
2020-07-19 11:47:19 +01:00
|
|
|
ObjectRover = ObjectType(GlyphRover)
|
2020-06-30 23:59:58 +01:00
|
|
|
|
2020-07-10 18:39:33 +01:00
|
|
|
// ObjectSmallRock is a small stashable rock
|
2020-07-19 11:47:19 +01:00
|
|
|
ObjectSmallRock = ObjectType(GlyphSmallRock)
|
2020-06-30 23:59:58 +01:00
|
|
|
|
2020-07-10 18:39:33 +01:00
|
|
|
// ObjectLargeRock is a large blocking rock
|
2020-07-19 11:47:19 +01:00
|
|
|
ObjectLargeRock = ObjectType(GlyphLargeRock)
|
2020-06-26 19:45:24 +01:00
|
|
|
)
|
|
|
|
|
2020-07-19 11:50:19 +01:00
|
|
|
// Glyph returns the glyph for this object type
|
|
|
|
func (o ObjectType) Glyph() Glyph {
|
|
|
|
switch o {
|
|
|
|
case ObjectNone:
|
|
|
|
return GlyphNone
|
|
|
|
case ObjectRover:
|
|
|
|
return GlyphRover
|
|
|
|
case ObjectSmallRock:
|
|
|
|
return GlyphSmallRock
|
|
|
|
case ObjectLargeRock:
|
|
|
|
return GlyphLargeRock
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Fatalf("Unknown object type: %c", o)
|
|
|
|
return GlyphNone
|
|
|
|
}
|
|
|
|
|
2020-07-03 17:00:04 +01:00
|
|
|
// Object represents an object in the world
|
|
|
|
type Object struct {
|
2020-07-19 11:47:19 +01:00
|
|
|
// The type of the object
|
|
|
|
Type ObjectType `json:"type"`
|
2020-07-03 17:00:04 +01:00
|
|
|
}
|
|
|
|
|
2020-06-30 23:59:58 +01:00
|
|
|
// IsBlocking checks if an object is a blocking object
|
2020-07-03 17:00:04 +01:00
|
|
|
func (o *Object) IsBlocking() bool {
|
2020-07-19 11:47:19 +01:00
|
|
|
var blocking = [...]ObjectType{
|
2020-07-10 18:39:33 +01:00
|
|
|
ObjectRover,
|
|
|
|
ObjectLargeRock,
|
2020-06-26 19:45:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range blocking {
|
2020-07-03 17:00:04 +01:00
|
|
|
if o.Type == t {
|
2020-06-26 19:45:24 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-06-30 23:59:58 +01:00
|
|
|
// IsStashable checks if an object is stashable
|
2020-07-03 17:00:04 +01:00
|
|
|
func (o *Object) IsStashable() bool {
|
2020-07-19 11:47:19 +01:00
|
|
|
var stashable = [...]ObjectType{
|
2020-07-10 18:39:33 +01:00
|
|
|
ObjectSmallRock,
|
2020-06-26 19:45:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range stashable {
|
2020-07-03 17:00:04 +01:00
|
|
|
if o.Type == t {
|
2020-06-26 19:45:24 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|