本文整理匯總了Golang中github.com/MobRulesGames/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
}
示例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
}
示例3: 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
}
}
示例4: 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
}
示例5: 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
}
}
示例6: 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
}
示例7: 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)
}
}
示例8: 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
}
示例9: 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)
}
}
示例10: 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
}
示例11: checkWinConditions
func (g *Game) checkWinConditions() {
return
// Check for explorer win conditions
explorer_win := false
if explorer_win {
base.Log().Printf("Explorers won - kaboom")
}
// Check for haunt win condition - all intruders dead
haunts_win := true
for i := range g.Ents {
if g.Ents[i].Side() == SideExplorers {
haunts_win = false
}
}
if haunts_win {
base.Log().Printf("Haunts won - kaboom")
}
}
示例12: Maintain
func (a *Move) Maintain(dt int64, g *game.Game, ae game.ActionExec) game.MaintenanceStatus {
if ae != nil {
exec := ae.(*moveExec)
a.ent = g.EntityById(ae.EntityId())
if len(exec.Path) == 0 {
base.Error().Printf("Got a move exec with a path length of 0: %v", exec)
return game.Complete
}
a.cost = exec.measureCost(a.ent, g)
if a.cost > a.ent.Stats.ApCur() {
base.Error().Printf("Got a move that required more ap than available: %v", exec)
base.Error().Printf("Path: %v", exec.Path)
return game.Complete
}
if a.cost == -1 {
base.Error().Printf("Got a move that followed an invalid path: %v", exec)
base.Error().Printf("Path: %v", exec.Path)
if a.ent == nil {
base.Error().Printf("ENT was Nil!")
} else {
x, y := a.ent.Pos()
v := g.ToVertex(x, y)
base.Error().Printf("Ent pos: (%d, %d) -> (%d)", x, y, v)
}
return game.Complete
}
algorithm.Map2(exec.Path, &a.path, func(v int) [2]int {
_, x, y := g.FromVertex(v)
return [2]int{x, y}
})
base.Log().Printf("Path Validated: %v", exec)
a.ent.Stats.ApplyDamage(-a.cost, 0, status.Unspecified)
src := g.ToVertex(a.ent.Pos())
graph := g.Graph(a.ent.Side(), true, nil)
a.drawPath(a.ent, g, graph, src)
}
// Do stuff
factor := float32(math.Pow(2, a.ent.Walking_speed))
dist := a.ent.DoAdvance(factor*float32(dt)/200, a.path[0][0], a.path[0][1])
for dist > 0 {
if len(a.path) == 1 {
a.ent.DoAdvance(0, 0, 0)
a.ent.Info.RoomsExplored[a.ent.CurrentRoom()] = true
a.ent = nil
return game.Complete
}
a.path = a.path[1:]
a.ent.Info.RoomsExplored[a.ent.CurrentRoom()] = true
dist = a.ent.DoAdvance(dist, a.path[0][0], a.path[0][1])
}
return game.InProgress
}
示例13: MakeGamePanel
func MakeGamePanel(script string, p *Player, data map[string]string, game_key mrgnet.GameKey) *GamePanel {
var gp GamePanel
gp.AnchorBox = gui.MakeAnchorBox(gui.Dims{1024, 768})
if p == nil {
p = &Player{}
}
base.Log().Printf("Script path: %s / %s", script, p.Script_path)
if script == "" {
script = p.Script_path
}
startGameScript(&gp, script, p, data, game_key)
return &gp
}
示例14: Respond
func (rc *RosterChooser) Respond(ui *gui.Gui, group gui.EventGroup) bool {
base.Log().Printf("RosterChooser.Respond")
if found, event := group.FindEvent('l'); found && event.Type == gin.Press {
rc.focus += rc.layout.Num_options
return true
}
if found, event := group.FindEvent('o'); found && event.Type == gin.Press {
rc.focus -= rc.layout.Num_options
return true
}
if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
x, y := event.Key.Cursor().Point()
gp := gui.Point{x, y}
if gp.Inside(rc.render.down) {
rc.focus += rc.layout.Num_options
return true
} else if gp.Inside(rc.render.up) {
rc.focus -= rc.layout.Num_options
return true
} else if gp.Inside(rc.render.all_options) {
for i := range rc.render.options {
if gp.Inside(rc.render.options[i]) {
rc.selector(i, rc.selected, true)
return true
}
}
} else if gp.Inside(rc.render.done) {
if rc.selector(-1, rc.selected, false) {
base.Log().Printf("calling on-complete")
rc.on_complete(rc.selected)
}
return true
} else if rc.on_undo != nil && gp.Inside(rc.render.undo) {
rc.on_undo()
return true
}
}
return false
}
示例15: Load
func (he *HouseEditor) Load(path string) error {
house, err := MakeHouseFromPath(path)
if err != nil {
return err
}
base.Log().Printf("Loaded %s\n", path)
house.Normalize()
he.house = *house
he.viewer.SetBounds()
for _, tab := range he.widgets {
tab.Reload()
}
return err
}