コード例 #1
0
ファイル: intruders.go プロジェクト: RickDakan/haunts
func execIntruder(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaNumParamsOk(L, 1, "ExecIntruder") {
			return 0
		}
		ent := game.LuaToEntity(L, a.game, -1)
		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.Active() {
			game.LuaDoError(L, fmt.Sprintf("Tried to ExecIntruder '%s', who is not active.", ent.Name))
			return 0
		}
		exec := <-ent.Ai.ActionExecs()
		if exec != nil {
			a.execs <- exec
		}
		<-a.pause
		return 0
	}
}
コード例 #2
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// 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
	}
}
コード例 #3
0
ファイル: intruders.go プロジェクト: RickDakan/haunts
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
	}
}
コード例 #4
0
ファイル: minion.go プロジェクト: FlyingCar/haunts
func execMinionFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		base.Log().Printf("Exec minion")
		if !game.LuaNumParamsOk(L, 1, "execMinion") {
			return 0
		}
		ent := game.LuaToEntity(L, a.game, -1)
		if ent == nil {
			game.LuaDoError(L, "Tried to execMinion entity which doesn't exist.")
			return 0
		}
		if ent.HauntEnt == nil || ent.HauntEnt.Level != game.LevelMinion {
			game.LuaDoError(L, fmt.Sprintf("Tried to execMinion entity with Id=%d, which is not a minion.", ent.Id))
			return 0
		}
		if !ent.Ai.Active() {
			game.LuaDoError(L, fmt.Sprintf("Tried to execMinion entity with Id=%d, which is not active.", ent.Id))
			return 0
		}
		exec := <-ent.Ai.ActionExecs()
		if exec != nil {
			a.execs <- exec
		}
		<-a.pause
		return 0
	}
}
コード例 #5
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// 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
	}
}
コード例 #6
0
ファイル: minion.go プロジェクト: RickDakan/haunts
func execMinion(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaNumParamsOk(L, 1, "ExecMinion") {
			return 0
		}
		ent := game.LuaToEntity(L, a.game, -1)
		if ent == nil {
			game.LuaDoError(L, "Tried to ExecMinion on an invalid entity.")
			return 0
		}
		if ent.HauntEnt == nil || ent.HauntEnt.Level != game.LevelMinion {
			game.LuaDoError(L, "Tried to ExecMinion on a non-minion.")
			return 0
		}
		if !ent.Ai.Active() {
			game.LuaDoError(L, fmt.Sprintf("Tried to ExecMinion '%s', who is not active.", ent.Name))
			return 0
		}
		exec := <-ent.Ai.ActionExecs()
		if exec != nil {
			a.execs <- exec
		}
		<-a.pause
		return 0
	}
}
コード例 #7
0
ファイル: entity.go プロジェクト: RickDakan/haunts
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
	}
}
コード例 #8
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// 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
	}
}
コード例 #9
0
ファイル: intruders.go プロジェクト: RickDakan/haunts
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
	}
}
コード例 #10
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// Performs a basic attack against the specifed target.
//    Format:
//    res = DoBasicAttack(attack, target)
//
//    Inputs:
//    attack - string  - Name of the attack to use.
//    target - integer - Entity id of the target of this attack.
//
//    Outputs:
//    res - table - Table containing the following values:
//                  hit (boolean) - true iff the attack hit its target.
//                  If the attack was invalid for some reason res will be nil.
func DoBasicAttackFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "DoBasicAttack", game.LuaString, game.LuaEntity) {
			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
		}
		target := game.LuaToEntity(L, a.ent.Game(), -1)
		if action == nil {
			game.LuaDoError(L, fmt.Sprintf("Tried to target an entity who doesn't exist."))
			return 0
		}
		attack, ok := action.(*actions.BasicAttack)
		if !ok {
			game.LuaDoError(L, fmt.Sprintf("Action '%s' is not a basic attack.", name))
			return 0
		}
		exec := attack.AiAttackTarget(me, target)
		if exec != nil {
			a.execs <- exec
			<-a.pause
			result := actions.GetBasicAttackResult(exec)
			if result == nil {
				L.PushNil()
			} else {
				L.NewTable()
				L.PushString("hit")
				L.PushBoolean(result.Hit)
				L.SetTable(-3)
			}
		} else {
			L.PushNil()
		}
		return 1
	}
}
コード例 #11
0
ファイル: entity.go プロジェクト: RickDakan/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
	}
}
コード例 #12
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// Performs an aoe attack against centered at the specified position.
//    Format:
//    target = BestAoeAttackPos(attack, extra_dist, spec)
//
//    Inputs:
//    attack     - string  - Name of the attack to use.
//    extra_dist - integer - Available distance to move before attacking.
//    spec       - string  - One of the following values:
//                           "allies ok", "minions ok", "enemies only"
//
//    Outputs:
//    pos  - table[x,y] - Position to place aoe for maximum results.
//    hits - array[ents] - Visible entities that will be in the aoe
func BestAoeAttackPosFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "BestAoeAttackPos", game.LuaString, game.LuaInteger, game.LuaString) {
			return 0
		}
		me := a.ent
		name := L.ToString(-3)
		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
		}
		var spec actions.AiAoeTarget
		switch L.ToString(-1) {
		case "allies ok":
			spec = actions.AiAoeHitAlliesOk
		case "minions ok":
			spec = actions.AiAoeHitMinionsOk
		case "enemies only":
			spec = actions.AiAoeHitNoAllies
		default:
			game.LuaDoError(L, fmt.Sprintf("'%s' is not a valid value of spec for BestAoeAttackPos().", L.ToString(-1)))
			return 0
		}
		x, y, hits := attack.AiBestTarget(me, L.ToInteger(-2), spec)
		game.LuaPushPoint(L, x, y)
		L.NewTable()
		for i := range hits {
			L.PushInteger(i + 1)
			game.LuaPushEntity(L, hits[i])
			L.SetTable(-3)
		}
		return 2
	}
}
コード例 #13
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// 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
	}
}
コード例 #14
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// Returns a list of all doors attached to the specified room.
//    Format
//    room = allDoorsOn(r)
//
//    Input:
//    r - room - A room.
//
//    Output:
//    doors - array[door] - List of all doors attached to the specified room.
func AllDoorsOn(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "allDoorsOn", game.LuaRoom) {
			return 0
		}
		room := game.LuaToRoom(L, a.ent.Game(), -1)
		if room == nil {
			game.LuaDoError(L, "Specified an invalid room.")
			return 0
		}

		L.NewTable()
		for i := range room.Doors {
			L.PushInteger(i + 1)
			game.LuaPushDoor(L, a.ent.Game(), room.Doors[i])
			L.SetTable(-3)
		}
		return 1
	}
}
コード例 #15
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// Returns a list of all doors between two rooms.
//    Format
//    doors = allDoorsBetween(r1, r2)
//
//    Input:
//    r1 - room - A room.
//    r2 - room - Another room.
//
//    Output:
//    doors - array[door] - List of all doors connecting r1 and r2.
func AllDoorsBetween(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "allDoorsBetween", game.LuaRoom, game.LuaRoom) {
			return 0
		}
		room1 := game.LuaToRoom(L, a.ent.Game(), -2)
		room2 := game.LuaToRoom(L, a.ent.Game(), -1)
		if room1 == nil || room2 == nil {
			game.LuaDoError(L, "AllDoorsBetween: Specified an invalid door.")
			return 0
		}

		// TODO: Check for floors!
		// if f1 != f2 {
		//   // Rooms on different floors can theoretically be connected in the
		//   // future by a stairway, but right now that doesn't happen.
		//   L.NewTable()
		//   return 1
		// }

		L.NewTable()
		count := 1
		for _, door1 := range room1.Doors {
			for _, door2 := range room2.Doors {
				_, d := a.ent.Game().House.Floors[0].FindMatchingDoor(room1, door1)
				if d == door2 {
					L.PushInteger(count)
					count++
					game.LuaPushDoor(L, a.ent.Game(), door1)
					L.SetTable(-3)
				}
			}
		}
		return 1
	}
}
コード例 #16
0
ファイル: entity.go プロジェクト: RickDakan/haunts
// Returns a list of all positions inside the specified room.
//    Format
//    ps = roomPositions(r)
//
//    Input:
//    r - room - A room.
//
//    Output:
//    ps - array[table[x,y]] - List of all position inside the specified room.
func RoomPositionsFunc(a *Ai) lua.GoFunction {
	return func(L *lua.State) int {
		if !game.LuaCheckParamsOk(L, "roomPositions", game.LuaRoom) {
			return 0
		}
		room := game.LuaToRoom(L, a.ent.Game(), -1)
		if room == nil {
			game.LuaDoError(L, "RoomPositions: Specified an invalid room.")
			return 0
		}

		L.NewTable()
		count := 1
		for x := room.X; x < room.X+room.Size.Dx; x++ {
			for y := room.Y; y < room.Y+room.Size.Dy; y++ {
				L.PushInteger(count)
				count++
				game.LuaPushPoint(L, x, y)
				L.SetTable(-3)
			}
		}
		return 1
	}
}