当前位置: 首页>>代码示例>>Golang>>正文


Golang game.LuaCheckParamsOk函数代码示例

本文整理汇总了Golang中github.com/runningwild/haunts/game.LuaCheckParamsOk函数的典型用法代码示例。如果您正苦于以下问题:Golang LuaCheckParamsOk函数的具体用法?Golang LuaCheckParamsOk怎么用?Golang LuaCheckParamsOk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LuaCheckParamsOk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NearbyUnexploredRoomsFunc

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
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:30,代码来源:entity.go

示例2: setIntruderMasterInfo

func setIntruderMasterInfo(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "SetEntityMasterInfo", game.LuaEntity, game.LuaString, game.LuaAnything) {
			return 0
		}
		ent := game.LuaToEntity(L, a.game, -3)
		if ent == nil {
			game.LuaDoError(L, "Tried to ExecIntruder on an invalid entity.")
			return 0
		}
		if ent.ExplorerEnt == nil {
			game.LuaDoError(L, "Tried to ExecIntruder on a non-intruder.")
			return 0
		}
		if ent.Ai_data == nil {
			ent.Ai_data = make(map[string]string)
		}
		if L.IsNil(-1) {
			delete(ent.Ai_data, L.ToString(-2))
		} else {
			ent.Ai_data[L.ToString(-2)] = L.ToString(-1)
		}
		return 0
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:25,代码来源:intruders.go

示例3: WaypointsFunc

func WaypointsFunc(me *game.Entity) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "Waypoints") {
			return 0
		}
		g := me.Game()
		L.NewTable()
		count := 0
		for _, wp := range g.Waypoints {
			if wp.Side != me.Side() {
				continue
			}
			count++
			L.PushInteger(count)
			L.NewTable()
			L.PushString("Name")
			L.PushString(wp.Name)
			L.SetTable(-3)
			L.PushString("Radius")
			L.PushNumber(wp.Radius)
			L.SetTable(-3)
			L.PushString("Pos")
			game.LuaPushPoint(L, int(wp.X), int(wp.Y))
			L.SetTable(-3)
			L.SetTable(-3)
		}
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:29,代码来源:entity.go

示例4: DoDoorToggleFunc

// Performs an Interact action to toggle the opened/closed state of a door.
//    Format
//    res = doDoorToggle(d)
//
//    Input:
//    d - door - A door.
//
//    Output:
//    res - boolean - True if the door was opened, false if it was closed.
//    res will be nil if the action could not be performed for some reason.
func DoDoorToggleFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "doDoorToggle", game.LuaDoor) {
			return 0
		}
		door := game.LuaToDoor(L, a.ent.Game(), -1)
		if door == nil {
			game.LuaDoError(L, "DoDoorToggle: Specified an invalid door.")
			return 0
		}

		var interact *actions.Interact
		for _, action := range a.ent.Actions {
			var ok bool
			interact, ok = action.(*actions.Interact)
			if ok {
				break
			}
		}
		if interact == nil {
			game.LuaDoError(L, fmt.Sprintf("Tried to toggle a door, but don't have an interact action."))
			L.PushNil()
			return 1
		}
		exec := interact.AiToggleDoor(a.ent, door)
		if exec != nil {
			a.execs <- exec
			<-a.pause
			L.PushBoolean(door.IsOpened())
		} else {
			L.PushNil()
		}
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:45,代码来源:entity.go

示例5: DoMoveFunc

// Performs a move action to the closest one of any of the specifed inputs
// points.  The movement can be restricted to not spend more than a certain
// amount of ap.
//    Format:
//    success, p = DoMove(dsts, max_ap)
//
//    Input:
//    dsts  - array[table[x,y]] - Array of all points that are acceptable
//                                destinations.
//    max_ap - integer - Maxmium ap to spend while doing this move, if the
//                       required ap exceeds this the entity will still move
//                       as far as possible towards a destination.
//
//    Output:
//    success = bool - True iff the move made it to a position in dsts.
//    p - table[x,y] - New position of this entity, or nil if the move failed.
func DoMoveFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "DoMove", game.LuaArray, game.LuaInteger) {
			return 0
		}
		me := a.ent
		max_ap := L.ToInteger(-1)
		L.Pop(1)
		cur_ap := me.Stats.ApCur()
		if max_ap > cur_ap {
			max_ap = cur_ap
		}
		n := int(L.ObjLen(-1))
		dsts := make([]int, n)[0:0]
		for i := 1; i <= n; i++ {
			L.PushInteger(i)
			L.GetTable(-2)
			x, y := game.LuaToPoint(L, -1)
			dsts = append(dsts, me.Game().ToVertex(x, y))
			L.Pop(1)
		}
		var move *actions.Move
		var ok bool
		for i := range me.Actions {
			move, ok = me.Actions[i].(*actions.Move)
			if ok {
				break
			}
		}
		if !ok {
			// TODO: what to do here?  This poor guy didn't have a move action :(
			L.PushNil()
			L.PushNil()
			return 2
		}
		exec := move.AiMoveToPos(me, dsts, max_ap)
		if exec != nil {
			a.execs <- exec
			<-a.pause
			// TODO: Need to get a resolution
			x, y := me.Pos()
			v := me.Game().ToVertex(x, y)
			complete := false
			for i := range dsts {
				if v == dsts[i] {
					complete = true
					break
				}
			}
			L.PushBoolean(complete)
			game.LuaPushPoint(L, x, y)
			base.Log().Printf("Finished move")
		} else {
			base.Log().Printf("Didn't bother moving")
			L.PushBoolean(true)
			L.PushNil()
		}
		return 2
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:76,代码来源:entity.go

示例6: DoInteractWithObjectFunc

func DoInteractWithObjectFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "DoInteractWithObject", game.LuaEntity) {
			return 0
		}
		object := game.LuaToEntity(L, a.ent.Game(), -1)
		var interact *actions.Interact
		for _, action := range a.ent.Actions {
			var ok bool
			interact, ok = action.(*actions.Interact)
			if ok {
				break
			}
		}
		if interact == nil {
			game.LuaDoError(L, "Tried to interact with an object, but don't have an interact action.")
			L.PushNil()
			return 1
		}
		exec := interact.AiInteractWithObject(a.ent, object)
		if exec != nil {
			a.execs <- exec
			<-a.pause
			L.PushBoolean(true)
		} else {
			L.PushNil()
		}
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:30,代码来源:entity.go

示例7: DoAoeAttackFunc

// Performs an aoe attack against centered at the specified position.
//    Format:
//    res = DoAoeAttack(attack, pos)
//
//    Inputs:
//    attack - string     - Name of the attack to use.
//    pos    - table[x,y] - Position to center the aoe around.
//
//    Outputs:
//    res - boolean - true if the action performed, nil otherwise.
func DoAoeAttackFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "DoAoeAttack", game.LuaString, game.LuaPoint) {
			return 0
		}
		me := a.ent
		name := L.ToString(-2)
		action := getActionByName(me, name)
		if action == nil {
			game.LuaDoError(L, fmt.Sprintf("Entity '%s' (id=%d) has no action named '%s'.", me.Name, me.Id, name))
			return 0
		}
		attack, ok := action.(*actions.AoeAttack)
		if !ok {
			game.LuaDoError(L, fmt.Sprintf("Action '%s' is not an aoe attack.", name))
			return 0
		}
		tx, ty := game.LuaToPoint(L, -1)
		exec := attack.AiAttackPosition(me, tx, ty)
		if exec != nil {
			a.execs <- exec
			<-a.pause
			L.PushBoolean(true)
		} else {
			L.PushNil()
		}
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:39,代码来源:entity.go

示例8: randFunc

func randFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "Rand", game.LuaInteger) {
			return 0
		}
		n := L.ToInteger(-1)
		L.PushInteger(int(a.game.Rand.Int63()%int64(n)) + 1)
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:10,代码来源:entity.go

示例9: RoomAreEqualFunc

func RoomAreEqualFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "RoomsAreEqual", game.LuaRoom, game.LuaRoom) {
			return 0
		}
		r1 := game.LuaToRoom(L, a.ent.Game(), -2)
		r2 := game.LuaToRoom(L, a.ent.Game(), -1)
		L.PushBoolean(r1 == r2)
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:11,代码来源:entity.go

示例10: RoomPathFunc

// 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
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:69,代码来源:entity.go

示例11: DoorIsOpenFunc

// Queries whether a door is currently open.
//    Format
//    open = doorIsOpen(d)
//
//    Input:
//    d - door - A door.
//
//    Output:
//    open - boolean - True if the door is open, false otherwise.
func DoorIsOpenFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "doorIsOpen", game.LuaDoor) {
			return 0
		}
		door := game.LuaToDoor(L, a.ent.Game(), -1)
		if door == nil {
			game.LuaDoError(L, "DoorIsOpen: Specified an invalid door.")
			return 0
		}
		L.PushBoolean(door.IsOpened())
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:23,代码来源:entity.go

示例12: AllPathablePointsFunc

// Returns an array of all points that can be reached by walking from a
// specific location that end in a certain general area.  Assumes that a 1x1
// unit is doing the walking.
//    Format:
//    points = AllPathablePoints(src, dst, min, max)
//
//    Inputs:
//    src - table[x,y] - Where the path starts.
//    dst - table[x,y] - Another point near where the path should go.
//    min - integer    - Minimum distance from dst that the path should end at.
//    max - integer    - Maximum distance from dst that the path should end at.
//
//    Outputs:
//    points - array[table[x,y]]
func AllPathablePointsFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "AllPathablePoints", game.LuaPoint, game.LuaPoint, game.LuaInteger, game.LuaInteger) {
			return 0
		}
		min := L.ToInteger(-2)
		max := L.ToInteger(-1)
		x1, y1 := game.LuaToPoint(L, -4)
		x2, y2 := game.LuaToPoint(L, -3)

		a.ent.Game().DetermineLos(x2, y2, max, grid)
		var dst []int
		for x := x2 - max; x <= x2+max; x++ {
			for y := y2 - max; y <= y2+max; y++ {
				if x > x2-min && x < x2+min && y > y2-min && y < y2+min {
					continue
				}
				if x < 0 || y < 0 || x >= len(grid) || y >= len(grid[0]) {
					continue
				}
				if !grid[x][y] {
					continue
				}
				dst = append(dst, a.ent.Game().ToVertex(x, y))
			}
		}
		vis := 0
		for i := range grid {
			for j := range grid[i] {
				if grid[i][j] {
					vis++
				}
			}
		}
		base.Log().Printf("Visible: %d", vis)
		graph := a.ent.Game().Graph(a.ent.Side(), true, nil)
		src := []int{a.ent.Game().ToVertex(x1, y1)}
		reachable := algorithm.ReachableDestinations(graph, src, dst)
		L.NewTable()
		base.Log().Printf("%d/%d reachable from (%d, %d) -> (%d, %d)", len(reachable), len(dst), x1, y1, x2, y2)
		for i, v := range reachable {
			_, x, y := a.ent.Game().FromVertex(v)
			L.PushInteger(i + 1)
			game.LuaPushPoint(L, x, y)
			L.SetTable(-3)
		}
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:63,代码来源:entity.go

示例13: DoorPositionsFunc

// Returns a list of all positions that the specified door can be opened and
// closed from.
//    Format
//    ps = doorPositions(d)
//
//    Input:
//    d - door - A door.
//
//    Output:
//    ps - array[table[x,y]] - List of all position this door can be opened
//    and closed from.
func DoorPositionsFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "DoorPositions", game.LuaDoor) {
			return 0
		}
		room := game.LuaToRoom(L, a.ent.Game(), -1)
		door := game.LuaToDoor(L, a.ent.Game(), -1)
		if door == nil || room == nil {
			game.LuaDoError(L, "DoorPositions: Specified an invalid door.")
			return 0
		}

		var x, y, dx, dy int
		switch door.Facing {
		case house.FarLeft:
			x = door.Pos
			y = room.Size.Dy - 1
			dx = 1
		case house.FarRight:
			x = room.Size.Dx - 1
			y = door.Pos
			dy = 1
		case house.NearLeft:
			x = -1
			y = door.Pos
			dy = 1
		case house.NearRight:
			x = door.Pos
			y = -1
			dx = 1
		default:
			game.LuaDoError(L, fmt.Sprintf("Found a door with a bad facing."))
		}
		L.NewTable()
		count := 1
		for i := 0; i < door.Width; i++ {
			L.PushInteger(count*2 - 1)
			game.LuaPushPoint(L, room.X+x+dx*i, room.Y+y+dy*i)
			L.SetTable(-3)
			L.PushInteger(count * 2)
			game.LuaPushPoint(L, room.X+x+dx*i+dy, room.Y+y+dy*i+dx)
			L.SetTable(-3)
			count++
		}
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:58,代码来源:entity.go

示例14: RoomContainingFunc

// 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
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:29,代码来源:entity.go

示例15: isActiveIntruder

func isActiveIntruder(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "IsActive", game.LuaEntity) {
			return 0
		}
		ent := game.LuaToEntity(L, a.game, -1)
		if ent == nil {
			game.LuaDoError(L, "Tried to IsActive on an invalid entity.")
			return 0
		}
		if ent.ExplorerEnt == nil {
			game.LuaDoError(L, "Tried to IsActive on a non-intruder.")
			return 0
		}
		L.PushBoolean(ent.Ai.Active())
		return 1
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:18,代码来源:intruders.go


注:本文中的github.com/runningwild/haunts/game.LuaCheckParamsOk函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。