Example #1
0
func (e *Entity) SwapPositionWith(other interfaces.Entity) {
	if !e.IsTangible() || !other.IsTangible() {
		log.Fatalf("Swap only makes sense for tangible entities. Got %v & %v",
			e.GetName(), other.GetName())
	}

	/* It's crucial that two tagnible entities don't end up on same tile */
	boardId, x, y := e.GetPosition()
	boardId2, x2, y2 := other.GetPosition()
	e.BoardId, e.X, e.Y = boardId2, x2, y2
	/* Can work since both entities are technically in the same place */
	other.SetPosition(boardId, x, y)

	/* Manually trigger trodden functions since we didn't SetPosition */
	for _, entity := range e.Game.GetEntitiesAtSpace(e.GetPosition()) {
		entity.Trodden(e)
	}

	/* other's reposition function will be called by SetPosition */
	e.RepositionFunction(boardId, x, y, boardId2, x2, y2)
}