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


Golang base.Log函数代码示例

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


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

示例1: AiMoveToPos

func (a *Move) AiMoveToPos(ent *game.Entity, dst []int, max_ap int) game.ActionExec {
	base.Log().Printf("PATH: Request move to %v", dst)
	graph := ent.Game().Graph(ent.Side(), false, nil)
	src := []int{ent.Game().ToVertex(ent.Pos())}
	_, path := algorithm.Dijkstra(graph, src, dst)
	base.Log().Printf("PATH: Found path of length %d", len(path))
	ppx, ppy := ent.Pos()
	if path == nil {
		return nil
	}
	_, xx, yy := ent.Game().FromVertex(path[len(path)-1])
	base.Log().Printf("PATH: %d,%d -> %d,%d", ppx, ppy, xx, yy)
	if ent.Stats.ApCur() < max_ap {
		max_ap = ent.Stats.ApCur()
	}
	path = limitPath(ent, src[0], path, max_ap)
	_, xx, yy = ent.Game().FromVertex(path[len(path)-1])
	base.Log().Printf("PATH: (limited) %d,%d -> %d,%d", ppx, ppy, xx, yy)
	if len(path) <= 1 {
		return nil
	}
	var exec moveExec
	exec.SetBasicData(ent, a)
	exec.Path = path
	return &exec
}
开发者ID:hilerchyn,项目名称:haunts,代码行数:26,代码来源:move.go

示例2: measureCost

func (exec *moveExec) measureCost(ent *game.Entity, g *game.Game) int {
	if len(exec.Path) == 0 {
		base.Error().Printf("Zero length path")
		return -1
	}
	if g.ToVertex(ent.Pos()) != exec.Path[0] {
		base.Error().Printf("Path doesn't begin at ent's position, %d != %d", g.ToVertex(ent.Pos()), exec.Path[0])
		return -1
	}
	graph := g.Graph(ent.Side(), true, nil)
	v := g.ToVertex(ent.Pos())
	cost := 0
	for _, step := range exec.Path[1:] {
		dsts, costs := graph.Adjacent(v)
		ok := false
		prev := v
		base.Log().Printf("Adj(%d):", v)
		for j := range dsts {
			base.Log().Printf("Node %d", dsts[j])
			if dsts[j] == step {
				cost += int(costs[j])
				v = dsts[j]
				ok = true
				break
			}
		}
		base.Log().Printf("%d -> %d: %t", prev, v, ok)
		if !ok {
			return -1
		}
	}
	return cost
}
开发者ID:hilerchyn,项目名称:haunts,代码行数:33,代码来源:move.go

示例3: loadHouse

func loadHouse(gp *GamePanel) lua.GoFunction {
	return func(L *lua.State) int {
		if !LuaCheckParamsOk(L, "LoadHouse", LuaString) {
			return 0
		}
		gp.script.syncStart()
		defer gp.script.syncEnd()

		name := L.ToString(-1)
		def := house.MakeHouseFromName(name)
		if def == nil || len(def.Floors) == 0 {
			base.Error().Printf("No house exists with the name '%s'.", name)
			return 0
		}
		gp.game = makeGame(def)
		gp.game.viewer.Edit_mode = true
		gp.game.script = gp.script
		base.Log().Printf("script = %p", gp.game.script)

		gp.AnchorBox = gui.MakeAnchorBox(gui.Dims{1024, 768})
		gp.AnchorBox.AddChild(gp.game.viewer, gui.Anchor{0.5, 0.5, 0.5, 0.5})
		gp.AnchorBox.AddChild(MakeOverlay(gp.game), gui.Anchor{0.5, 0.5, 0.5, 0.5})

		base.Log().Printf("Done making stuff")
		return 0
	}
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:27,代码来源:script.go

示例4: 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

示例5: AiAttackPosition

func (a *AoeAttack) AiAttackPosition(ent *game.Entity, x, y int) game.ActionExec {
	if !ent.HasLos(x, y, 1, 1) {
		base.Log().Printf("Don't have los")
		return nil
	}
	if a.Ap > ent.Stats.ApCur() {
		base.Log().Printf("Don't have the ap")
		return nil
	}
	var exec aoeExec
	exec.SetBasicData(ent, a)
	exec.X, exec.Y = x, y
	return &exec
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:14,代码来源:aoe_attack.go

示例6: 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

示例7: masterRoutine

// Need a goroutine for each ai - all things will go through is so that things
// stay synchronized
func (a *Ai) masterRoutine() {
	for {
		select {
		case <-a.terminate:
			if a.watcher != nil {
				a.watcher.Close()
			}
			close(a.active_query)
			return

		case a.active = <-a.active_set:
			if a.active == false {
				if a.ent == nil {
					base.Log().Printf("Evaluating = false")
				} else {
					base.Log().Printf("Ent %p inactivated", a.ent)
				}
				a.evaluating = false
			}

		case a.active_query <- a.active:

		case <-a.exec_query:
			if a.active {
				select {
				case a.pause <- struct{}{}:
				default:
				}
			}
			if a.active && !a.evaluating {
				a.evaluating = true
				go func() {
					if a.ent == nil {
						base.Log().Printf("Eval master")
					} else {
						base.Log().Printf("Eval ent: %p", a.ent)
					}
					base.Log().Printf("Evaluating lua script: %s", a.Prog)
					// Reset the execution limit in case it was set to 0 due to a
					// previous error
					a.L.SetExecutionLimit(2500000)

					// DoString will panic, and we can catch that, calling it manually
					// will exit() if it fails, which we cannot catch
					a.L.DoString("Think()")
					if a.ent == nil {
						base.Log().Printf("Completed master")
					} else {
						base.Log().Printf("Completed ent: %p", a.ent)
					}
					a.active_set <- false
					a.execs <- nil
					base.Log().Printf("Sent nil value")
				}()
			}
		}
	}
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:60,代码来源:ai.go

示例8: setCursor

// Returns true iff the position specified is a valid position to click in the
// text area.  Also sets everything up so that if te.Entry.entering can be set
// to true to begin editing at that position.
func (te *TextEntry) setCursor(mx, my int) bool {
	if !pointInsideRect(mx, my, te.Entry.bounds.x, te.Entry.bounds.y, te.Entry.bounds.dx, te.Entry.bounds.dy) {
		te.Entry.ghost.offset = -1
		return false
	}

	d := base.GetDictionary(te.Button.Text.Size)
	last_dx := 0
	base.Log().Printf("Inside")
	te.Entry.ghost.index = -1
	for i := range te.Entry.text {
		w := int(d.StringWidth(te.Entry.text[0 : i+1]))
		avg := (last_dx + w) / 2
		if pointInsideRect(mx, my, te.Entry.bounds.x, te.Entry.bounds.y, avg, te.Entry.bounds.dy) {
			te.Entry.ghost.offset = last_dx
			te.Entry.ghost.index = i
			break
		}
		last_dx = w
	}
	if te.Entry.ghost.index < 0 {
		te.Entry.ghost.offset = int(d.StringWidth(te.Entry.text))
		te.Entry.ghost.index = len(te.Entry.text)
	}
	return true
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:29,代码来源:ui_text_entry.go

示例9: RenderAt

func (b *Button) RenderAt(x, y int) {
	gl.Color4ub(255, 255, 255, byte(b.shade*255))
	if b.Texture.Path != "" {
		b.Texture.Data().RenderNatural(b.X+x, b.Y+y)
		b.bounds.x = b.X + x
		b.bounds.y = b.Y + y
		b.bounds.dx = b.Texture.Data().Dx()
		b.bounds.dy = b.Texture.Data().Dy()
	} else {
		d := base.GetDictionary(b.Text.Size)
		b.bounds.x = b.X + x
		b.bounds.y = b.Y + y
		b.bounds.dx = int(d.StringWidth(b.Text.String))
		b.bounds.dy = int(d.MaxHeight())
		base.Log().Printf("Button '%s' @ %d %d %d %d", b.Text.String, b.bounds.x, b.bounds.y, b.bounds.dx, b.bounds.dy)
		var just gui.Justification
		switch b.Text.Justification {
		case "center":
			just = gui.Center
			b.bounds.x -= b.bounds.dx / 2
		case "left":
			just = gui.Left
		case "right":
			just = gui.Right
			b.bounds.x -= b.bounds.dx
		default:
			just = gui.Center
			b.bounds.x -= b.bounds.dx / 2
			b.Text.Justification = "center"
			base.Warn().Printf("Failed to indicate valid aligmnent, '%s' is not valid.", b.Text.Justification)
		}
		d.RenderString(b.Text.String, float64(b.X+x), float64(b.Y+y), 0, d.MaxHeight(), just)
	}
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:34,代码来源:ui_button.go

示例10: execMinionFunc

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

示例11: InsertVersusMenu

func InsertVersusMenu(ui gui.WidgetParent, replace func(gui.WidgetParent) error) error {
	// return doChooserMenu(ui, makeChooseVersusMetaMenu, replace, inserter(insertGoalMenu))
	chooser, done, err := makeChooseVersusMetaMenu()
	if err != nil {
		return err
	}
	ui.AddChild(chooser)
	go func() {
		m := <-done
		ui.RemoveChild(chooser)
		if m != nil && len(m) == 1 {
			base.Log().Printf("Chose: %v", m)
			switch m[0] {
			case "Select House":
				ui.AddChild(MakeGamePanel("versus/basic.lua", nil, map[string]string{"map": "select"}, ""))
			case "Random House":
				ui.AddChild(MakeGamePanel("versus/basic.lua", nil, map[string]string{"map": "random"}, ""))
			case "Continue":
				ui.AddChild(MakeGamePanel("versus/basic.lua", nil, map[string]string{"map": "continue"}, ""))
			default:
				base.Error().Printf("Unknown meta choice '%s'", m[0])
				return
			}
		} else {
			err := replace(ui)
			if err != nil {
				base.Error().Printf("Error replacing menu: %v", err)
			}
		}
	}()
	return nil
}
开发者ID:RickDakan,项目名称:haunts,代码行数:32,代码来源:ui_versus.go

示例12: spawnEnts

// Distributes the ents among the spawn points.  Since this is done randomly
// it might not work, so there is a very small chance that not all spawns will
// have an ent given to them, even if it is possible to distrbiute them
// properly.  Regardless, at least some will be spawned.
func spawnEnts(g *Game, ents []*Entity, spawns []*house.SpawnPoint) {
	sort.Sort(orderSpawnsSmallToBig(spawns))
	sanity := 100
	var places []entSpawnPair
	for sanity > 0 {
		sanity--
		places = places[0:0]
		sort.Sort(orderEntsBigToSmall(ents))
		//slightly shuffle the ents
		for i := range ents {
			j := i + rand.Intn(5) - 2
			if j >= 0 && j < len(ents) {
				ents[i], ents[j] = ents[j], ents[i]
			}
		}
		// Go through each ent and try to place it in an unused spawn point
		used_spawns := make(map[*house.SpawnPoint]bool)
		for _, ent := range ents {
			for _, spawn := range spawns {
				if used_spawns[spawn] {
					continue
				}
				if spawn.Dx < ent.Dx || spawn.Dy < ent.Dy {
					continue
				}
				used_spawns[spawn] = true
				places = append(places, entSpawnPair{ent, spawn})
				break
			}
		}
		if len(places) == len(spawns) {
			break
		}
	}
	if sanity > 0 {
		base.Log().Printf("Placed all objects with %d sanity remaining", sanity)
	} else {
		base.Warn().Printf("Only able to place %d out of %d objects", len(places), len(spawns))
	}
	for _, place := range places {
		place.ent.X = float64(place.spawn.X + rand.Intn(place.spawn.Dx-place.ent.Dx+1))
		place.ent.Y = float64(place.spawn.Y + rand.Intn(place.spawn.Dy-place.ent.Dy+1))
		g.viewer.AddDrawable(place.ent)
		g.Ents = append(g.Ents, place.ent)
		base.Log().Printf("Using object '%s' at (%.0f, %.0f)", place.ent.Name, place.ent.X, place.ent.Y)
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:51,代码来源:game.go

示例13: LuaDecodeValue

// Decodes a value from the reader and pushes it onto the stack
func LuaDecodeValue(r io.Reader, L *lua.State, g *Game) error {
	var le luaEncodable
	err := binary.Read(r, binary.LittleEndian, &le)
	if err != nil {
		return err
	}
	switch le {
	case luaEncBool:
		var v byte
		err = binary.Read(r, binary.LittleEndian, &v)
		L.PushBoolean(v == 1)
	case luaEncNumber:
		var f float64
		err = binary.Read(r, binary.LittleEndian, &f)
		L.PushNumber(f)
	case luaEncNil:
		L.PushNil()
	case luaEncEntity:
		var id uint64
		err = binary.Read(r, binary.LittleEndian, &id)
		ent := g.EntityById(EntityId(id))
		LuaPushEntity(L, ent)
		if ent != nil {
			base.Log().Printf("LUA: Push Ent %s", ent.Name)
		} else {
			base.Log().Printf("LUA: Push Ent NIL")
		}
	case luaEncTable:
		err = LuaDecodeTable(r, L, g)
	case luaEncString:
		var length uint32
		err = binary.Read(r, binary.LittleEndian, &length)
		if err != nil {
			return err
		}
		sb := make([]byte, length)
		err = binary.Read(r, binary.LittleEndian, &sb)
		L.PushString(string(sb))
	default:
		return errors.New(fmt.Sprintf("Unknown lua value id == %d.", le))
	}
	if err != nil {
		return err
	}
	return nil
}
开发者ID:RickDakan,项目名称:haunts,代码行数:47,代码来源:script_utils.go

示例14: LoadAi

func (e *Entity) LoadAi() {
	filename := e.Ai_path.String()
	if e.Ai_file_override != "" {
		filename = e.Ai_file_override.String()
	}
	if filename == "" {
		base.Log().Printf("No ai for %s", e.Name)
		e.Ai = inactiveAi{}
		return
	}
	ai_maker(filename, e.Game(), e, &e.Ai, EntityAi)
	if e.Ai == nil {
		e.Ai = inactiveAi{}
		base.Log().Printf("Failed to make Ai for '%s' with %s", e.Name, filename)
	} else {
		base.Log().Printf("Made Ai for '%s' with %s", e.Name, filename)
	}
}
开发者ID:RickDakan,项目名称:haunts,代码行数:18,代码来源:entity.go

示例15: Activate

func (a *Ai) Activate() {
	if a.ent != nil {
		base.Log().Printf("Activated entity: %v", a.ent.Name)
	}
	reload := false
	for {
		select {
		case <-a.watcher.Event:
			reload = true
		default:
			goto no_more_events
		}
	}
no_more_events:
	if reload {
		a.setupLuaState()
		base.Log().Printf("Reloaded lua state for '%p'", a)
	}
	a.active_set <- true
}
开发者ID:FlyingCar,项目名称:haunts,代码行数:20,代码来源:ai.go


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