Documentation ¶
Overview ¶
world document
world project world.go
Index ¶
- Constants
- func BACK() relativeDirection
- func EAST() absoluteDirection
- func FRONT() relativeDirection
- func LEFT() relativeDirection
- func NORTH() absoluteDirection
- func RIGHT() relativeDirection
- func SOUTH() absoluteDirection
- func WEST() absoluteDirection
- type AbsoluteDirection
- type Actor
- type ActorID
- type ActorSchedule
- func (self ActorSchedule) Add(actor_id ActorID, time uint64) ActorSchedule
- func (self ActorSchedule) Copy() ActorSchedule
- func (self ActorSchedule) Len() int
- func (self ActorSchedule) Less(i, j int) bool
- func (self ActorSchedule) Next(time uint64) (ActorTime, bool)
- func (self ActorSchedule) Pos(actor_time ActorTime) int
- func (self ActorSchedule) PosActorID(actor_id ActorID) int
- func (self ActorSchedule) Remove(actor_time ActorTime) (ActorSchedule, bool)
- func (self ActorSchedule) Swap(i, j int)
- type ActorTime
- type Actors
- type BaseBuilding
- type Building
- type Buildings
- type Coord
- type Creature
- type CreatureActor
- func (self CreatureActor) Add(creature_id CreatureId, actor_id ActorID) (CreatureActor, error)
- func (self CreatureActor) Copy() CreatureActor
- func (self CreatureActor) GetActor(creature_id CreatureId) (ActorID, bool)
- func (self CreatureActor) GetCreature(actor_id ActorID) (CreatureId, bool)
- func (self CreatureActor) IsSane() error
- func (self CreatureActor) RemoveActor(actor_id ActorID) (CreatureActor, bool)
- func (self CreatureActor) RemoveCreature(creature_id CreatureId) (CreatureActor, bool)
- type CreatureActorError
- type CreatureId
- type CreatureLocation
- func (self CreatureLocation) Add(creature_id CreatureId, location Location) (CreatureLocation, error)
- func (self CreatureLocation) Copy() CreatureLocation
- func (self CreatureLocation) GetCreature(loc Location) (CreatureId, bool)
- func (self CreatureLocation) GetLocation(creature_id CreatureId) (Location, bool)
- func (self CreatureLocation) IsSane() error
- func (self CreatureLocation) Move(creature_id CreatureId, location Location) (CreatureLocation, error)
- func (self CreatureLocation) RemoveCreature(creature_id CreatureId) (CreatureLocation, bool)
- func (self CreatureLocation) RemoveLocation(location Location) (CreatureLocation, bool)
- type CreatureLocationError
- type Creatures
- func (self Creatures) Add(creature Creature) (Creatures, CreatureId)
- func (self Creatures) Copy() Creatures
- func (self Creatures) Get(creature_id CreatureId) (Creature, bool)
- func (self Creatures) Set(creature_id CreatureId, creature Creature) Creatures
- func (self Creatures) Spawn() (Creatures, CreatureId, Creature)
- type Dynamic
- type Facer
- type Floor
- type Level
- type Location
- type MaybePassable
- type ModelId
- type OrientedBuilding
- type Position
- func (self Position) Facing() AbsoluteDirection
- func (self Position) MoveAbsolute(absdir AbsoluteDirection, steps int) Position
- func (self Position) MoveBackward(steps int) Position
- func (self Position) MoveForward(steps int) Position
- func (self Position) MoveLeft(steps int) Position
- func (self Position) MoveRelative(reldir RelativeDirection, steps int) Position
- func (self Position) MoveRight(steps int) Position
- func (self Position) SetF(f AbsoluteDirection) Position
- func (self Position) SetLocation(location Location) Position
- func (self Position) SetX(x Coord) Position
- func (self Position) SetY(y Coord) Position
- func (self Position) ToLocation() Location
- func (self Position) Turn(rel_dir RelativeDirection, steps int) Position
- type RelativeDirection
- type Wall
- type World
Constants ¶
const ( CA_INSANE_LENGTH = CreatureActorError(iota) CA_INSANE_BIJECTION CA_CREATURE_ALREADY_IN CA_ACTOR_ALREADY_IN )
const ( CL_NOOP = CreatureLocationError(iota) CL_INSANE_LENGTH CL_INSANE_BIJECTION CL_CREATURE_ALREADY_IN CL_LOCATION_ALREADY_IN CL_NOT_FOUND CL_OCCUPIED )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AbsoluteDirection ¶
type AbsoluteDirection interface { // Returns 0, 1, 2 or 3 for EAST, NORTH, WEST and SOUTH. Value() int // Apply a relative direction to an absolute direction to get another absolute // direction. For example, LEFT of WEST is SOUTH. Add(b RelativeDirection) AbsoluteDirection // Returns the X and Y increments corresponding to the current direction. // For example, `EAST.DxDy()` returns `1, 0`. Because moving east increments // your x and leaves y alone. `SOUTH.DxDy()` returns `0, -1`, because south // points toward negative y. DxDy() (Coord, Coord) // contains filtered or unexported methods }
Relative directions can be applied to absolute directions to get a new absolute direction.
type Actor ¶
type Actor struct{}
An Actor is anything that can be at the origin of an Action (see the IA package for Actions). It can be a creature, a trap, a mechanism, etc. An Actor is not aware of its unique identifier, you have to keep track of it yourself.
type ActorSchedule ¶
type ActorSchedule struct { Actor_times []ActorTime Next_stability_index uint64 // To ensure stable sorting. }
func MakeActorSchedule ¶
func MakeActorSchedule() ActorSchedule
func (ActorSchedule) Add ¶
func (self ActorSchedule) Add(actor_id ActorID, time uint64) ActorSchedule
func (ActorSchedule) Copy ¶
func (self ActorSchedule) Copy() ActorSchedule
func (ActorSchedule) Less ¶
func (self ActorSchedule) Less(i, j int) bool
func (ActorSchedule) Next ¶
func (self ActorSchedule) Next(time uint64) (ActorTime, bool)
Find an actor that should be acting at the provided time. Brute force search that does ot assume that the actors are sorted by time.
func (ActorSchedule) Pos ¶
func (self ActorSchedule) Pos(actor_time ActorTime) int
func (ActorSchedule) PosActorID ¶
func (self ActorSchedule) PosActorID(actor_id ActorID) int
func (ActorSchedule) Remove ¶
func (self ActorSchedule) Remove(actor_time ActorTime) (ActorSchedule, bool)
func (ActorSchedule) Swap ¶
func (self ActorSchedule) Swap(i, j int)
type Actors ¶
type Actors struct { // NextIDprivate is exported only so that it can be encoded by gob. // Do not use. // It starts at 0 and increases each time the Add method is called. NextIDprivate ActorID // ContentPrivate is exported only so that it can be encoded by gob. // Do not use. Use the Actors.Content() method instead. ContentPrivate map[ActorID]Actor }
An Actors object holds a collection of Actor objects s identified by an ActorID. It contains a map of Actors indexed by their unique identifier. It also manages unique identifiers. Use the Add method to get a new unique identifier for an Actor.
func MakeActors ¶
func MakeActors() Actors
MakeActors creates and returns an empty collection of Actors.
func (Actors) Add ¶
Add returns a new Actors object to which the given Actor actor is added. The method also returns the ActorID that was given to actor.
type BaseBuilding ¶
type BaseBuilding struct { // Underscore means that this field is public but should not be used. // Please use the Model() function to read it, and do NOT change it. // It is public only because Gob requires it. I may spend time writing // a GobEncoder later to hide this field again, but I do not want to // spend time maintaining code that is still so likely to change. Model_ ModelId }
func MakeBaseBuilding ¶
func MakeBaseBuilding(model ModelId) BaseBuilding
func (BaseBuilding) Model ¶
func (self BaseBuilding) Model() ModelId
type Buildings ¶
func MakeBuildings ¶
func MakeBuildings() Buildings
type Coord ¶
type Coord int
Used to represent either an absolute position, or a relative position. Kind of messy compared with the rotations. However, the x and y coordinates are easy to get right, as their algebra is not modulo 4, so I do not need a safety net in the form of type checking here.
type Creature ¶
type Creature struct {
F AbsoluteDirection
}
func MakeCreature ¶
func MakeCreature() Creature
type CreatureActor ¶
type CreatureActor struct { // Upper case for debugging and for Gob, not so that you use it. Ca map[CreatureId]ActorID Ac map[ActorID]CreatureId }
func MakeCreatureActor ¶
func MakeCreatureActor() CreatureActor
func (CreatureActor) Add ¶
func (self CreatureActor) Add(creature_id CreatureId, actor_id ActorID) (CreatureActor, error)
func (CreatureActor) Copy ¶
func (self CreatureActor) Copy() CreatureActor
func (CreatureActor) GetActor ¶
func (self CreatureActor) GetActor(creature_id CreatureId) (ActorID, bool)
func (CreatureActor) GetCreature ¶
func (self CreatureActor) GetCreature(actor_id ActorID) (CreatureId, bool)
func (CreatureActor) IsSane ¶
func (self CreatureActor) IsSane() error
func (CreatureActor) RemoveActor ¶
func (self CreatureActor) RemoveActor(actor_id ActorID) (CreatureActor, bool)
func (CreatureActor) RemoveCreature ¶
func (self CreatureActor) RemoveCreature(creature_id CreatureId) (CreatureActor, bool)
type CreatureActorError ¶
type CreatureActorError int
func (CreatureActorError) Error ¶
func (self CreatureActorError) Error() string
type CreatureId ¶
type CreatureId uint64
Each creature in the world is identified with a unique ID. A creature does not know its own ID. This is to avoid inconsistencies. Indeed, creatures are contained in a map[CreatureId]Creature.
type CreatureLocation ¶
type CreatureLocation struct { Cl map[CreatureId]Location Lc map[Location]CreatureId }
func MakeCreatureLocation ¶
func MakeCreatureLocation() CreatureLocation
func (CreatureLocation) Add ¶
func (self CreatureLocation) Add(creature_id CreatureId, location Location) (CreatureLocation, error)
func (CreatureLocation) Copy ¶
func (self CreatureLocation) Copy() CreatureLocation
func (CreatureLocation) GetCreature ¶
func (self CreatureLocation) GetCreature(loc Location) (CreatureId, bool)
func (CreatureLocation) GetLocation ¶
func (self CreatureLocation) GetLocation(creature_id CreatureId) (Location, bool)
func (CreatureLocation) IsSane ¶
func (self CreatureLocation) IsSane() error
func (CreatureLocation) Move ¶
func (self CreatureLocation) Move(creature_id CreatureId, location Location) (CreatureLocation, error)
func (CreatureLocation) RemoveCreature ¶
func (self CreatureLocation) RemoveCreature(creature_id CreatureId) (CreatureLocation, bool)
func (CreatureLocation) RemoveLocation ¶
func (self CreatureLocation) RemoveLocation(location Location) (CreatureLocation, bool)
type CreatureLocationError ¶
type CreatureLocationError int
func (CreatureLocationError) Error ¶
func (self CreatureLocationError) Error() string
type Creatures ¶
type Creatures struct { Next_id CreatureId Content map[CreatureId]Creature }
func MakeCreatures ¶
func MakeCreatures() Creatures
type Facer ¶
type Facer interface {
Facing() AbsoluteDirection
}
type Floor ¶
type Floor struct { OrientedBuilding MaybePassable }
type Level ¶
type Level struct { Floors Buildings Ceilings Buildings Walls [4]Buildings // Sorted by facing. Columns Buildings Dynamic Dynamic Actors Actors Creatures Creatures CreatureLocation CreatureLocation CreatureActor CreatureActor ActorSchedule ActorSchedule }
func (*Level) IsPassable ¶
func (level *Level) IsPassable(location Location, direction AbsoluteDirection) bool
func (Level) SetActorSchedule ¶
func (self Level) SetActorSchedule(actor_schedule ActorSchedule) Level
type Location ¶
type Location struct {
X, Y Coord
}
func (Location) MoveAbsolute ¶
func (self Location) MoveAbsolute(absdir AbsoluteDirection, steps int) Location
func (Location) ToPosition ¶
func (self Location) ToPosition(facing AbsoluteDirection) Position
type MaybePassable ¶
type MaybePassable struct {
Passable_ bool
}
func (MaybePassable) IsPassable ¶
func (self MaybePassable) IsPassable() bool
type OrientedBuilding ¶
type OrientedBuilding struct { BaseBuilding F AbsoluteDirection }
func MakeOrientedBuilding ¶
func MakeOrientedBuilding(model ModelId, facing AbsoluteDirection) OrientedBuilding
func (OrientedBuilding) Facing ¶
func (building OrientedBuilding) Facing() AbsoluteDirection
type Position ¶
type Position struct { Location F AbsoluteDirection }
func (Position) Facing ¶
func (self Position) Facing() AbsoluteDirection
func (Position) MoveAbsolute ¶
func (self Position) MoveAbsolute(absdir AbsoluteDirection, steps int) Position
func (Position) MoveBackward ¶
func (Position) MoveForward ¶
func (Position) MoveRelative ¶
func (self Position) MoveRelative(reldir RelativeDirection, steps int) Position
func (Position) SetF ¶
func (self Position) SetF(f AbsoluteDirection) Position
func (Position) SetLocation ¶
func (Position) ToLocation ¶
type RelativeDirection ¶
type RelativeDirection interface { // Returns 0, 1, 2 or 3 for FRONT, LEFT, BACK or RIGHT. Value() int // Returns -1 for LEFT, +1 for RIGHT, 0 for the rest. Sign() int // Combines two relative directions together. Add(rel RelativeDirection) RelativeDirection // contains filtered or unexported methods }
The rotation arithmetics is abstracted behind these two interfaces. You can combine relative directions together. For example, left of left is back. Back of right is left. Note that this is commutative: right of back is left too.
type Wall ¶
type Wall struct { BaseBuilding MaybePassable }
type World ¶
type World struct { Player_id ActorID // Later, there will also be a LevelId too in here. Level Level // Later, there will be many. Time uint64 // Nanoseconds. }
func (World) SetActorSchedule ¶
func (world World) SetActorSchedule(actor_schedule ActorSchedule) World