Documentation
ΒΆ
Overview ΒΆ
Package spawn provides entity placement capabilities for game spaces. Purpose: Complete spawn engine implementation per ADR-0013 with split-aware architecture, environment integration, capacity analysis, and adaptive room scaling.
Package spawn provides intelligent entity placement and spawning capabilities.
Index ΒΆ
- Variables
- type BasicSelectablesRegistry
- type BasicSpawnEngine
- func (e *BasicSpawnEngine) AnalyzeRoomStructure(roomID string) RoomStructureInfo
- func (e *BasicSpawnEngine) ConnectToEventBus(bus events.EventBus)
- func (e *BasicSpawnEngine) PopulateRoom(ctx context.Context, roomID string, config SpawnConfig) (SpawnResult, error)
- func (e *BasicSpawnEngine) PopulateSpace(ctx context.Context, roomOrGroup interface{}, config SpawnConfig) (SpawnResult, error)
- func (e *BasicSpawnEngine) PopulateSplitRooms(ctx context.Context, connectedRooms []string, config SpawnConfig) (SpawnResult, error)
- func (e *BasicSpawnEngine) ValidateSpawnConfig(config SpawnConfig) error
- type BasicSpawnEngineConfig
- type ConstraintSolver
- type EntityGroup
- type EntityPair
- type EntitySpawnedEvent
- type FormationConstraints
- type FormationPattern
- type FormationScaling
- type LineOfSightRules
- type PathingConstraints
- type PlacementRules
- type PlayerSpawnChoice
- type QuantitySpec
- type RelativePosition
- type RoomModification
- type RoomScaledEvent
- type RoomSplit
- type RoomStructureInfo
- type ScalingConfig
- type SelectablesRegistry
- type SeparationConstraints
- type SimpleRoomEntity
- type SpatialConstraints
- type SpawnConfig
- type SpawnEngine
- type SpawnFailure
- type SpawnPattern
- type SpawnResult
- type SpawnStrategy
- type SpawnZone
- type SpawnedEntity
- type SplitRecommendedEvent
- type Team
- type TeamCohesionRules
- type TeamConfig
- type TeamPlacementStrategy
Constants ΒΆ
This section is empty.
Variables ΒΆ
var ( // EntitySpawnedTopic publishes events when entities are spawned EntitySpawnedTopic = events.DefineTypedTopic[EntitySpawnedEvent]("spawn.entity.spawned") // SplitRecommendedTopic publishes events when room splitting is recommended SplitRecommendedTopic = events.DefineTypedTopic[SplitRecommendedEvent]("spawn.split.recommended") // RoomScaledTopic publishes events when rooms are scaled for capacity RoomScaledTopic = events.DefineTypedTopic[RoomScaledEvent]("spawn.room.scaled") )
Functions ΒΆ
This section is empty.
Types ΒΆ
type BasicSelectablesRegistry ΒΆ
type BasicSelectablesRegistry struct {
// contains filtered or unexported fields
}
BasicSelectablesRegistry implements SelectablesRegistry. Purpose: Simple entity selection registry for Phase 1 implementation.
func NewBasicSelectablesRegistry ΒΆ
func NewBasicSelectablesRegistry() *BasicSelectablesRegistry
NewBasicSelectablesRegistry creates a new registry. Purpose: Constructor for entity selection table management.
func (*BasicSelectablesRegistry) GetEntities ΒΆ
GetEntities implements SelectablesRegistry.GetEntities
func (*BasicSelectablesRegistry) ListTables ΒΆ
func (r *BasicSelectablesRegistry) ListTables() []string
ListTables implements SelectablesRegistry.ListTables
func (*BasicSelectablesRegistry) RegisterTable ΒΆ
func (r *BasicSelectablesRegistry) RegisterTable(tableID string, entities []core.Entity) error
RegisterTable implements SelectablesRegistry.RegisterTable
type BasicSpawnEngine ΒΆ
type BasicSpawnEngine struct {
// contains filtered or unexported fields
}
BasicSpawnEngine implements SpawnEngine interface. Purpose: Complete implementation per ADR-0013 with environment integration and split-aware spawning.
func NewBasicSpawnEngine ΒΆ
func NewBasicSpawnEngine(config BasicSpawnEngineConfig) *BasicSpawnEngine
NewBasicSpawnEngine creates a new spawn engine with the specified configuration. Purpose: Standard constructor following toolkit config pattern with proper dependency injection.
func (*BasicSpawnEngine) AnalyzeRoomStructure ΒΆ
func (e *BasicSpawnEngine) AnalyzeRoomStructure(roomID string) RoomStructureInfo
AnalyzeRoomStructure implements SpawnEngine.AnalyzeRoomStructure
func (*BasicSpawnEngine) ConnectToEventBus ΒΆ added in v0.1.1
func (e *BasicSpawnEngine) ConnectToEventBus(bus events.EventBus)
ConnectToEventBus connects all typed topics to the event bus
func (*BasicSpawnEngine) PopulateRoom ΒΆ
func (e *BasicSpawnEngine) PopulateRoom( ctx context.Context, roomID string, config SpawnConfig, ) (SpawnResult, error)
PopulateRoom implements SpawnEngine.PopulateRoom
func (*BasicSpawnEngine) PopulateSpace ΒΆ
func (e *BasicSpawnEngine) PopulateSpace( ctx context.Context, roomOrGroup interface{}, config SpawnConfig, ) (SpawnResult, error)
PopulateSpace implements SpawnEngine.PopulateSpace
func (*BasicSpawnEngine) PopulateSplitRooms ΒΆ
func (e *BasicSpawnEngine) PopulateSplitRooms( ctx context.Context, connectedRooms []string, config SpawnConfig, ) (SpawnResult, error)
PopulateSplitRooms implements SpawnEngine.PopulateSplitRooms
func (*BasicSpawnEngine) ValidateSpawnConfig ΒΆ
func (e *BasicSpawnEngine) ValidateSpawnConfig(config SpawnConfig) error
ValidateSpawnConfig implements SpawnEngine.ValidateSpawnConfig
type BasicSpawnEngineConfig ΒΆ
type BasicSpawnEngineConfig struct {
ID string
SpatialHandler spatial.QueryHandler
EnvironmentHandler *environments.BasicQueryHandler
SelectablesReg SelectablesRegistry
// EventBus removed - use ConnectToEventBus() method after creation
EnableEvents bool
MaxAttempts int
}
BasicSpawnEngineConfig configures a BasicSpawnEngine. Purpose: Configuration struct following toolkit patterns for dependency injection.
type ConstraintSolver ΒΆ
type ConstraintSolver struct {
// contains filtered or unexported fields
}
ConstraintSolver validates and enforces spatial constraints during spawning. Purpose: Phase 3 implementation of constraint validation per ADR-0013.
func NewConstraintSolver ΒΆ
func NewConstraintSolver() *ConstraintSolver
NewConstraintSolver creates a new constraint solver with default settings. Purpose: Standard constructor for constraint validation system.
func (*ConstraintSolver) FindValidPositions ΒΆ
func (cs *ConstraintSolver) FindValidPositions( room spatial.Room, entity core.Entity, constraints SpatialConstraints, existingEntities []SpawnedEntity, maxPositions int, ) ([]spatial.Position, error)
FindValidPositions finds all positions that satisfy constraints. Purpose: Generate valid placement options for constraint-aware spawning.
func (*ConstraintSolver) ValidatePosition ΒΆ
func (cs *ConstraintSolver) ValidatePosition( room spatial.Room, position spatial.Position, entity core.Entity, constraints SpatialConstraints, existingEntities []SpawnedEntity, ) error
ValidatePosition checks if a position satisfies all spatial constraints. Purpose: Core constraint validation for entity placement.
type EntityGroup ΒΆ
type EntityGroup struct {
ID string `json:"id"`
Type string `json:"type"`
SelectionTable string `json:"selection_table"`
Quantity QuantitySpec `json:"quantity"`
}
EntityGroup represents a group of entities to spawn. Purpose: Defines entity type, selection table, and quantity for spawning.
type EntityPair ΒΆ
EntityPair represents a relationship between two entity types
type EntitySpawnedEvent ΒΆ added in v0.1.1
type EntitySpawnedEvent struct {
EntityID string `json:"entity_id"`
EntityType string `json:"entity_type,omitempty"`
Position spatial.Position `json:"position"`
RoomID string `json:"room_id"`
SpawnType string `json:"spawn_type"` // "scattered", "formation", "player_choice", "clustered"
SpawnGroupID string `json:"spawn_group_id,omitempty"`
Constraints []string `json:"constraints,omitempty"`
SpawnedAt time.Time `json:"spawned_at"`
}
EntitySpawnedEvent contains data for entity spawning events
type FormationConstraints ΒΆ
type FormationConstraints struct {
MinSpacing float64 `json:"min_spacing"`
RequiredSpace float64 `json:"required_space"`
WallClearance float64 `json:"wall_clearance"`
}
FormationConstraints define requirements for formation placement
type FormationPattern ΒΆ
type FormationPattern struct {
Name string `json:"name"`
Positions []RelativePosition `json:"positions"`
Scaling FormationScaling `json:"scaling"`
Constraints FormationConstraints `json:"constraints"`
}
FormationPattern defines a structured arrangement of entities. Purpose: Specifies precise positioning patterns for coordinated entity placement.
type FormationScaling ΒΆ
type FormationScaling struct {
AllowRotation bool `json:"allow_rotation"`
AllowStretching bool `json:"allow_stretching"`
PreserveRatios bool `json:"preserve_ratios"`
}
FormationScaling controls how formations adapt to space constraints
type LineOfSightRules ΒΆ
type LineOfSightRules struct {
RequiredSight []EntityPair `json:"required_sight"`
BlockedSight []EntityPair `json:"blocked_sight"`
}
LineOfSightRules define visibility requirements between entities
type PathingConstraints ΒΆ
type PathingConstraints struct {
MaintainExitAccess bool `json:"maintain_exit_access"`
MinPathWidth float64 `json:"min_path_width"`
}
PathingConstraints define movement and accessibility requirements
type PlacementRules ΒΆ
type PlacementRules struct {
MaintainExitAccess bool `json:"maintain_exit_access"`
MinPathWidth float64 `json:"min_path_width"`
PreferredAreas []string `json:"preferred_areas"`
}
PlacementRules define how entities should be positioned
type PlayerSpawnChoice ΒΆ
type PlayerSpawnChoice struct {
PlayerID string `json:"player_id"`
ZoneID string `json:"zone_id"`
Position spatial.Position `json:"position"`
}
PlayerSpawnChoice represents a player's choice of spawn position
type QuantitySpec ΒΆ
type QuantitySpec struct {
Fixed *int `json:"fixed,omitempty"`
}
QuantitySpec specifies how many entities to spawn. Purpose: Supports fixed quantities, dice expressions, and ranges for flexible spawning.
type RelativePosition ΒΆ
type RelativePosition struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Priority int `json:"priority"`
}
RelativePosition defines a position relative to formation center
type RoomModification ΒΆ
type RoomModification struct {
Type string `json:"type"`
RoomID string `json:"room_id"`
OldValue interface{} `json:"old_value"`
NewValue interface{} `json:"new_value"`
Reason string `json:"reason"`
}
RoomModification describes changes made to rooms during spawning. Purpose: Tracks room scaling and other adaptive changes for debugging and rollback.
type RoomScaledEvent ΒΆ added in v0.1.1
type RoomScaledEvent struct {
RoomID string `json:"room_id"`
OldCapacity int `json:"old_capacity"`
NewCapacity int `json:"new_capacity"`
ScaleReason string `json:"scale_reason"`
ScaleType string `json:"scale_type"` // "expand", "contract", "optimize"
ScaledAt time.Time `json:"scaled_at"`
}
RoomScaledEvent indicates when a room's capacity has been scaled
type RoomSplit ΒΆ
type RoomSplit struct {
SuggestedSize spatial.Dimensions `json:"suggested_size"`
ConnectionPoints []spatial.Position `json:"connection_points"`
SplitReason string `json:"split_reason"`
EntityDistribution map[string]int `json:"entity_distribution"`
}
RoomSplit describes a recommended room split configuration. Purpose: Passthrough recommendations from environment package for client decision-making.
type RoomStructureInfo ΒΆ
type RoomStructureInfo struct {
IsSplit bool `json:"is_split"`
ConnectedRooms []string `json:"connected_rooms"`
PrimaryRoomID string `json:"primary_room_id"`
}
RoomStructureInfo describes the room configuration used for spawning. Purpose: Indicates whether spawning used single or split-room configuration.
type ScalingConfig ΒΆ
type ScalingConfig struct {
Enabled bool `json:"enabled"`
ScalingFactor float64 `json:"scaling_factor"`
PreserveAspect bool `json:"preserve_aspect"`
EmitEvents bool `json:"emit_events"`
}
ScalingConfig controls adaptive room scaling behavior
type SelectablesRegistry ΒΆ
type SelectablesRegistry interface {
// RegisterTable registers a selection table for use in spawn configurations
RegisterTable(tableID string, entities []core.Entity) error
// GetEntities retrieves entities from a registered table
GetEntities(tableID string, quantity int) ([]core.Entity, error)
// ListTables returns the IDs of all registered tables
ListTables() []string
}
SelectablesRegistry manages selection tables for entity spawning. Purpose: Interface for registering and accessing entity selection tables.
type SeparationConstraints ΒΆ
type SeparationConstraints struct {
MinTeamDistance float64 `json:"min_team_distance"`
TeamPlacement TeamPlacementStrategy `json:"team_placement"`
}
SeparationConstraints define minimum distances between teams
type SimpleRoomEntity ΒΆ
type SimpleRoomEntity struct {
// contains filtered or unexported fields
}
SimpleRoomEntity implements core.Entity for event publishing. Purpose: Minimal entity implementation for spawn event sources.
func (*SimpleRoomEntity) GetID ΒΆ
func (r *SimpleRoomEntity) GetID() string
GetID returns the room entity ID
func (*SimpleRoomEntity) GetType ΒΆ
func (r *SimpleRoomEntity) GetType() string
GetType returns the room entity type
type SpatialConstraints ΒΆ
type SpatialConstraints struct {
MinDistance map[string]float64 `json:"min_distance"`
LineOfSight LineOfSightRules `json:"line_of_sight"`
WallProximity float64 `json:"wall_proximity"`
AreaOfEffect map[string]float64 `json:"area_of_effect"`
PathingRules PathingConstraints `json:"pathing_rules"`
}
SpatialConstraints define spatial requirements and restrictions
type SpawnConfig ΒΆ
type SpawnConfig struct {
// What to spawn
EntityGroups []EntityGroup `json:"entity_groups"`
// How to spawn
Pattern SpawnPattern `json:"pattern"`
TeamConfiguration *TeamConfig `json:"team_config,omitempty"`
// Constraints
SpatialRules SpatialConstraints `json:"spatial_rules"`
Placement PlacementRules `json:"placement"`
// Behavior
Strategy SpawnStrategy `json:"strategy"`
AdaptiveScaling *ScalingConfig `json:"adaptive_scaling,omitempty"`
// Player spawn zones and choices
PlayerSpawnZones []SpawnZone `json:"player_spawn_zones,omitempty"`
PlayerChoices []PlayerSpawnChoice `json:"player_choices,omitempty"`
}
SpawnConfig specifies how to spawn entities in a room. Purpose: Complete configuration for entity placement following ADR-0013 patterns.
type SpawnEngine ΒΆ
type SpawnEngine interface {
// Core spawning - works with single rooms or split room configurations
PopulateSpace(ctx context.Context, roomOrGroup interface{}, config SpawnConfig) (SpawnResult, error)
// Legacy single-room interface for backwards compatibility
PopulateRoom(ctx context.Context, roomID string, config SpawnConfig) (SpawnResult, error)
// Multi-room spawning for split room scenarios
PopulateSplitRooms(ctx context.Context, connectedRooms []string, config SpawnConfig) (SpawnResult, error)
// Configuration validation
ValidateSpawnConfig(config SpawnConfig) error
// Room structure analysis for split-awareness
AnalyzeRoomStructure(roomID string) RoomStructureInfo
}
SpawnEngine provides entity placement capabilities for game spaces. Purpose: Core interface for all entity spawning functionality per ADR-0013. Supports split-aware spawning, capacity analysis, and adaptive room scaling.
type SpawnFailure ΒΆ
SpawnFailure represents an entity that could not be placed. Purpose: Error tracking for debugging placement issues and constraint violations.
type SpawnPattern ΒΆ
type SpawnPattern string
SpawnPattern defines how entities are arranged in space. Purpose: Categorizes different spatial arrangement strategies per ADR-0013.
const ( // PatternScattered distributes entities randomly across available space PatternScattered SpawnPattern = "scattered" // PatternFormation uses structured arrangements PatternFormation SpawnPattern = "formation" // PatternClustered groups entities with spacing PatternClustered SpawnPattern = "clustered" // PatternTeamBased separates teams into distinct areas PatternTeamBased SpawnPattern = "team_based" // PatternPlayerChoice allows players to choose positions PatternPlayerChoice SpawnPattern = "player_choice" )
type SpawnResult ΒΆ
type SpawnResult struct {
Success bool `json:"success"`
SpawnedEntities []SpawnedEntity `json:"spawned_entities"`
Failures []SpawnFailure `json:"failures"`
RoomModifications []RoomModification `json:"room_modifications"`
SplitRecommendations []RoomSplit `json:"split_recommendations"`
RoomStructure RoomStructureInfo `json:"room_structure"`
}
SpawnResult contains the results of a spawn operation. Purpose: Complete outcome of entity placement including successes, failures, and room modifications.
type SpawnStrategy ΒΆ
type SpawnStrategy string
SpawnStrategy defines the spawning approach. Purpose: Controls randomization vs deterministic behavior in entity placement.
const ( // StrategyRandomized uses random placement within constraints StrategyRandomized SpawnStrategy = "randomized" // StrategyDeterministic produces consistent results StrategyDeterministic SpawnStrategy = "deterministic" // StrategyBalanced optimizes for gameplay balance StrategyBalanced SpawnStrategy = "balanced" )
type SpawnZone ΒΆ
type SpawnZone struct {
ID string `json:"id"`
Area spatial.Rectangle `json:"area"`
EntityTypes []string `json:"entity_types"`
MaxEntities int `json:"max_entities"`
}
SpawnZone defines an area where players can choose spawn positions. Purpose: Restricts player spawn choices to specific rectangular areas with type filtering.
type SpawnedEntity ΒΆ
type SpawnedEntity struct {
Entity core.Entity `json:"entity"`
Position spatial.Position `json:"position"`
RoomID string `json:"room_id"`
}
SpawnedEntity represents an entity that was successfully placed. Purpose: Contains entity reference, final position, and room assignment.
type SplitRecommendedEvent ΒΆ added in v0.1.1
type SplitRecommendedEvent struct {
RoomID string `json:"room_id"`
CurrentCapacity int `json:"current_capacity"`
RequiredCapacity int `json:"required_capacity"`
RecommendationType string `json:"recommendation_type"` // "split", "expand", "redistribute"
Reason string `json:"reason"`
Timestamp time.Time `json:"timestamp"`
}
SplitRecommendedEvent indicates when room splitting is recommended for capacity
type Team ΒΆ
type Team struct {
ID string `json:"id"`
EntityTypes []string `json:"entity_types"`
Formation *FormationPattern `json:"formation,omitempty"`
PreferredZone string `json:"preferred_zone"`
Cohesion float64 `json:"cohesion"`
}
Team represents a group of entities that should be placed together. Purpose: Defines entity types, formation, and cohesion settings for a tactical unit.
type TeamCohesionRules ΒΆ
type TeamCohesionRules struct {
KeepFriendliesTogether bool `json:"keep_friendlies_together"`
KeepEnemiesTogether bool `json:"keep_enemies_together"`
MinTeamSeparation float64 `json:"min_team_separation"`
}
TeamCohesionRules define how teams are kept together
type TeamConfig ΒΆ
type TeamConfig struct {
Teams []Team `json:"teams"`
CohesionRules TeamCohesionRules `json:"cohesion_rules"`
SeparationRules SeparationConstraints `json:"separation_rules"`
}
TeamConfig configures team-based spawning. Purpose: Defines team separation rules and cohesion constraints for tactical entity placement.
type TeamPlacementStrategy ΒΆ
type TeamPlacementStrategy string
TeamPlacementStrategy defines how teams are positioned relative to each other
const ( // TeamPlacementCorners places teams in room corners TeamPlacementCorners TeamPlacementStrategy = "corners" // TeamPlacementOppositeSides places teams on opposite sides TeamPlacementOppositeSides TeamPlacementStrategy = "opposite_sides" // TeamPlacementRandom places teams randomly with separation TeamPlacementRandom TeamPlacementStrategy = "random" )