func (self *Region) GetEvent(evt_type events.EventType, body string, origin entities.Entity) *events.Event { str_origin := "" if origin != nil { str_origin = origin.ID() } return &events.Event{self.ID(), evt_type, str_origin, body} }
func (self *Region) RemoveEntity(entity entities.Entity) { // Tell everyone else that the entity is leaving. self.Broadcast(self.GetEvent(events.REGION_EXIT, entity.ID(), entity)) // Find the entity location := -1 for i, e := range self.entities { if *e == entity { location = i break } } if location == -1 { log.Println("Could not find entity to remove!") return } // ...and remove it self.entities = append(self.entities[:location], self.entities[location+1:]...) }
func (self *Region) AddEntity(entity entities.Entity) { // Add the entity to the list of entities. self.entities = append(self.entities, &entity) // Tell everyone else that the entity is here. x, y := entity.BlockingPosition() self.Broadcast( self.GetEvent( events.REGION_ENTRANCE, fmt.Sprintf( "%s\n%f %f", entity.BlockingString(), x, y, ), entity, ), ) // Tell the entity about everyone else. for _, regEnt := range self.entities { if regEnt == &entity { continue } x, y := (*regEnt).BlockingPosition() entity.Receive() <- self.GetEvent( events.REGION_ENTRANCE, fmt.Sprintf( "%s\n%f %f", <-((*regEnt).String()), x, y, ), *regEnt, ) } }