コード例 #1
0
ファイル: entity.go プロジェクト: genbattle/haunts
func NearbyUnexploredRoomsFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "NearbyUnexploredRooms") {
			return 0
		}

		me := a.ent
		g := me.Game()
		graph := g.RoomGraph()
		var unexplored []int
		for room_num, _ := range g.House.Floors[0].Rooms {
			if !me.Info.RoomsExplored[room_num] {
				adj, _ := graph.Adjacent(room_num)
				for i := range adj {
					if me.Info.RoomsExplored[adj[i]] || adj[i] == me.CurrentRoom() {
						unexplored = append(unexplored, room_num)
						break
					}
				}
			}
		}
		L.NewTable()
		for i := range unexplored {
			L.PushInteger(i + 1)
			game.LuaPushRoom(L, a.game, a.game.House.Floors[0].Rooms[unexplored[i]])
			L.SetTable(-3)
		}
		return 1
	}
}
コード例 #2
0
ファイル: entity.go プロジェクト: genbattle/haunts
// Returns a list of rooms representing a path from src to dst.  The path will
// not include src, but will include dst.  This function will return nil if
// the path requires going through more than a single unexplored room, this
// means that you can use this to path to an unexplored room, but you cannot
// use it to path to a room further in the house than that.
// rooms.
//    Format
//    path = roomPath(src, dst)
//
//    Input:
//    src - Room to start the path from.
//    dst - Room to end the path at.
//
//    Output:
//    path - array - A list of rooms that connect src to dst, excluding src
//    but including dst.
func RoomPathFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "roomPath", game.LuaRoom, game.LuaRoom) {
			return 0
		}

		me := a.ent
		g := me.Game()
		graph := g.RoomGraph()
		r1 := game.LuaToRoom(L, g, -2)
		r2 := game.LuaToRoom(L, g, -1)
		if r1 == nil || r2 == nil {
			game.LuaDoError(L, fmt.Sprintf("Referenced one or more invalid rooms."))
			return 0
		}

		L.PushString("room")
		L.GetTable(-3)
		r1_index := L.ToInteger(-1)
		L.Pop(1)

		L.PushString("room")
		L.GetTable(-2)
		r2_index := L.ToInteger(-1)
		L.Pop(1)

		cost, path := algorithm.Dijkstra(graph, []int{r1_index}, []int{r2_index})
		if cost == -1 {
			L.PushNil()
			return 1
		}
		num_unexplored := 0
		for _, v := range path {
			if !me.Info.RoomsExplored[v] {
				num_unexplored++
			}
		}
		if num_unexplored > 1 {
			L.PushNil()
			return 1
		}
		L.NewTable()
		for i, v := range path {
			if i == 0 {
				continue
			} // Skip this one because we're in it already
			L.PushInteger(i)
			game.LuaPushRoom(L, g, g.House.Floors[0].Rooms[v])
			L.SetTable(-3)
		}
		return 1
	}
}
コード例 #3
0
ファイル: entity.go プロジェクト: genbattle/haunts
// Returns the room that the specified entity is currently in.  The specified
// entity must be in los of a unit on the acting entity's team, or be on the
// acting entity's team, otherwise this function returns nil.
//    Format
//    r = roomContaining(id)
//
//    Input:
//    id - An entity id.
//
//    Output:
//    r - room - The room the specified entity is in, or nil if it can't be
//    seen right now.
func RoomContainingFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "roomContaining", game.LuaEntity) {
			return 0
		}
		ent := game.LuaToEntity(L, a.ent.Game(), -1)
		side := a.ent.Side()
		x, y := a.ent.Pos()
		dx, dy := a.ent.Dims()
		if ent == nil || (ent.Side() != side && !a.ent.Game().TeamLos(side, x, y, dx, dy)) {
			L.PushNil()
		} else {
			game.LuaPushRoom(L, ent.Game(), ent.Game().House.Floors[0].Rooms[ent.CurrentRoom()])
		}
		return 1
	}
}