本文整理汇总了Golang中github.com/runningwild/haunts/base.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: getLos
func getLos(gp *GamePanel) lua.GoFunction {
return func(L *lua.State) int {
if !LuaCheckParamsOk(L, "GetLos", LuaEntity) {
return 0
}
ent := LuaToEntity(L, gp.game, -1)
if ent == nil {
base.Error().Printf("Tried to GetLos on an invalid entity.")
return 0
}
if ent.los == nil || ent.los.grid == nil {
base.Error().Printf("Tried to GetLos on an entity without vision.")
return 0
}
L.NewTable()
count := 0
for x := range ent.los.grid {
for y := range ent.los.grid[x] {
if ent.los.grid[x][y] {
count++
L.PushInteger(count)
LuaPushPoint(L, x, y)
L.SetTable(-3)
}
}
}
return 1
}
}
示例3: 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
}
示例4: setLosMode
func setLosMode(gp *GamePanel) lua.GoFunction {
return func(L *lua.State) int {
if !LuaCheckParamsOk(L, "SetLosMode", LuaString, LuaAnything) {
return 0
}
gp.script.syncStart()
defer gp.script.syncEnd()
side_str := L.ToString(-2)
var mode_str string
if L.IsString(-1) {
mode_str = L.ToString(-1)
} else {
mode_str = "rooms"
}
var side Side
switch side_str {
case "denizens":
side = SideHaunt
case "intruders":
side = SideExplorers
default:
base.Error().Printf("Cannot pass '%s' as first parameters of setLosMode()", side_str)
return 0
}
switch mode_str {
case "none":
gp.game.SetLosMode(side, LosModeNone, nil)
case "blind":
gp.game.SetLosMode(side, LosModeBlind, nil)
case "all":
gp.game.SetLosMode(side, LosModeAll, nil)
case "entities":
gp.game.SetLosMode(side, LosModeEntities, nil)
case "rooms":
if !L.IsTable(-1) {
base.Error().Printf("The last parameter to setLosMode should be an array of rooms if mode == 'rooms'")
return 0
}
L.PushNil()
all_rooms := gp.game.House.Floors[0].Rooms
var rooms []*house.Room
for L.Next(-2) != 0 {
index := L.ToInteger(-1)
if index < 0 || index > len(all_rooms) {
base.Error().Printf("Tried to reference room #%d which doesn't exist.", index)
continue
}
rooms = append(rooms, all_rooms[index])
L.Pop(1)
}
gp.game.SetLosMode(side, LosModeRooms, rooms)
default:
base.Error().Printf("Unknown los mode '%s'", mode_str)
return 0
}
return 0
}
}
示例5: Maintain
func (a *AoeAttack) Maintain(dt int64, g *game.Game, ae game.ActionExec) game.MaintenanceStatus {
if ae != nil {
a.exec = ae.(*aoeExec)
a.targets = a.getTargetsAt(g, a.exec.X, a.exec.Y)
if a.Current_ammo > 0 {
a.Current_ammo--
}
a.ent = g.EntityById(ae.EntityId())
if !a.ent.HasLos(a.exec.X, a.exec.Y, 1, 1) {
base.Error().Printf("Entity %d tried to target position (%d, %d) with an aoe but doesn't have los to it: %v", a.ent.Id, a.exec.X, a.exec.Y, a.exec)
return game.Complete
}
if a.Ap > a.ent.Stats.ApCur() {
base.Error().Printf("Got an aoe attack that required more ap than available: %v", a.exec)
return game.Complete
}
a.ent.Stats.ApplyDamage(-a.Ap, 0, status.Unspecified)
// Track this information for the ais - the attacking ent will only
// remember one ent that it hit, but that's ok
for _, target := range a.targets {
if target.Side() != a.ent.Side() {
target.Info.LastEntThatAttackedMe = a.ent.Id
a.ent.Info.LastEntThatIAttacked = target.Id
}
}
}
if a.ent.Sprite().State() != "ready" {
return game.InProgress
}
for _, target := range a.targets {
if target.Stats.HpCur() > 0 && target.Sprite().State() != "ready" {
return game.InProgress
}
}
a.ent.TurnToFace(a.exec.X, a.exec.Y)
for _, target := range a.targets {
target.TurnToFace(a.ent.Pos())
}
a.ent.Sprite().Command(a.Animation)
for _, target := range a.targets {
if g.DoAttack(a.ent, target, a.Strength, a.Kind) {
for _, name := range a.Conditions {
target.Stats.ApplyCondition(status.MakeCondition(name))
}
target.Stats.ApplyDamage(0, -a.Damage, a.Kind)
if target.Stats.HpCur() <= 0 {
target.Sprite().CommandN([]string{"defend", "killed"})
} else {
target.Sprite().CommandN([]string{"defend", "damaged"})
}
} else {
target.Sprite().CommandN([]string{"defend", "undamaged"})
}
}
return game.Complete
}
示例6: setWaypoint
func setWaypoint(gp *GamePanel) lua.GoFunction {
return func(L *lua.State) int {
if !LuaCheckParamsOk(L, "SetWaypoint", LuaString, LuaString, LuaPoint, LuaFloat) {
return 0
}
gp.script.syncStart()
defer gp.script.syncEnd()
var wp waypoint
side_str := L.ToString(-3)
switch side_str {
case "intruders":
wp.Side = SideExplorers
case "denizens":
wp.Side = SideHaunt
default:
base.Error().Printf("Specified '%s' for the side parameter in SetWaypoint, must be 'intruders' or 'denizens'.", side_str)
return 0
}
wp.Name = L.ToString(-4)
// Remove any existing waypoint by the same name
algorithm.Choose2(&gp.game.Waypoints, func(w waypoint) bool {
return w.Name != wp.Name
})
px, py := LuaToPoint(L, -2)
wp.X = float64(px)
wp.Y = float64(py)
wp.Radius = L.ToNumber(-1)
gp.game.Waypoints = append(gp.game.Waypoints, wp)
return 0
}
}
示例7: removeWaypoint
func removeWaypoint(gp *GamePanel) lua.GoFunction {
return func(L *lua.State) int {
if !LuaCheckParamsOk(L, "RemoveWaypoint", LuaString) {
return 0
}
gp.script.syncStart()
defer gp.script.syncEnd()
hit := false
name := L.ToString(-1)
for i := 0; i < len(gp.game.Waypoints); i++ {
if gp.game.Waypoints[i].Name == name {
hit = true
gp.game.viewer.RemoveFloorDrawable(&gp.game.Waypoints[i])
l := len(gp.game.Waypoints)
gp.game.Waypoints[i] = gp.game.Waypoints[l-1]
gp.game.Waypoints = gp.game.Waypoints[0 : l-1]
}
}
if !hit {
base.Error().Printf("RemoveWaypoint on waypoint '%s' which doesn't exist.", name)
return 0
}
return 0
}
}
示例8: MakeAction
func MakeAction(name string) Action {
f, ok := action_map[name]
if !ok {
base.Error().Printf("Unable to find an Action named '%s'", name)
}
return f()
}
示例9: Maintain
func (a *SummonAction) Maintain(dt int64, g *game.Game, ae game.ActionExec) game.MaintenanceStatus {
if ae != nil {
exec := ae.(*summonExec)
ent := g.EntityById(exec.Ent)
if ent == nil {
base.Error().Printf("Got a summon action without a valid entity.")
return game.Complete
}
a.ent = ent
_, a.cx, a.cy = a.ent.Game().FromVertex(exec.Pos)
a.ent.Stats.ApplyDamage(-a.Ap, 0, status.Unspecified)
a.spawn = game.MakeEntity(a.Ent_name, a.ent.Game())
if a.Current_ammo > 0 {
a.Current_ammo--
}
}
if a.ent.Sprite().State() == "ready" {
a.ent.TurnToFace(a.cx, a.cy)
a.ent.Sprite().Command(a.Animation)
a.spawn.Stats.OnBegin()
a.ent.Game().SpawnEntity(a.spawn, a.cx, a.cy)
return game.Complete
}
return game.InProgress
}
示例10: makeAi
func makeAi(path string, g *game.Game, ent *game.Entity, dst_iface *game.Ai, kind game.AiKind) {
ai_struct := new(Ai)
ai_struct.path = path
var err error
ai_struct.watcher, err = fsnotify.NewWatcher()
if err != nil {
base.Warn().Printf("Unable to create a filewatcher - '%s' will not reload ai files dynamically: %v", path, err)
ai_struct.watcher = nil
}
ai_struct.ent = ent
ai_struct.game = g
ai_struct.active_set = make(chan bool)
ai_struct.active_query = make(chan bool)
ai_struct.exec_query = make(chan struct{})
ai_struct.pause = make(chan struct{})
ai_struct.terminate = make(chan struct{})
ai_struct.execs = make(chan game.ActionExec)
ai_struct.kind = kind
err = ai_struct.setupLuaState()
if err != nil {
base.Error().Printf("Unable to make ai: %v", err)
if ai_struct.watcher != nil {
ai_struct.watcher.Close()
}
dst_iface = nil
return
}
go ai_struct.masterRoutine()
*dst_iface = ai_struct
}
示例11: LuaPushSmartFunctionTable
func LuaPushSmartFunctionTable(L *lua.State, ft FunctionTable) {
// Copy it just in case - I can't imagine someone changing it after passing
// it to this function, but I don't want to take any chances.
myft := make(FunctionTable)
for n, f := range ft {
myft[n] = f
}
names := make([]string, len(myft))[0:0]
for name := range myft {
names = append(names, name)
}
sort.Strings(names)
valid_selectors := "["
for i, name := range names {
if i > 0 {
valid_selectors += ", "
}
valid_selectors += fmt.Sprintf("'%s'", name)
}
valid_selectors += "]."
L.NewTable()
L.PushString("__index")
L.PushGoFunctionAsCFunction(func(L *lua.State) int {
name := L.ToString(-1)
if f, ok := myft[name]; ok {
f()
} else {
base.Error().Printf("'%s' is not a valid selector, valid seletors are %s", name, valid_selectors)
L.PushNil()
}
return 1
})
L.SetTable(-3)
}
示例12: PopSpawnRegexp
func PopSpawnRegexp() {
if len(spawn_regex) == 0 {
base.Error().Printf("Tried to pop an empty stack.")
return
}
spawn_regex = spawn_regex[0 : len(spawn_regex)-1]
}
示例13: 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
}
}
示例14: InsertStartMenu
func InsertStartMenu(ui gui.WidgetParent) error {
var sm StartMenu
datadir := base.GetDataDir()
err := base.LoadAndProcessObject(filepath.Join(datadir, "ui", "start", "layout.json"), "json", &sm.layout)
if err != nil {
return err
}
sm.buttons = []ButtonLike{
&sm.layout.Menu.Continue,
&sm.layout.Menu.Versus,
&sm.layout.Menu.Online,
&sm.layout.Menu.Settings,
}
sm.layout.Menu.Continue.f = func(interface{}) {}
sm.layout.Menu.Versus.f = func(interface{}) {
ui.RemoveChild(&sm)
ui.AddChild(MakeGamePanel("versus/basic.lua", nil, nil))
}
sm.layout.Menu.Settings.f = func(interface{}) {}
sm.layout.Menu.Online.f = func(interface{}) {
ui.RemoveChild(&sm)
err := InsertOnlineMenu(ui)
if err != nil {
base.Error().Printf("Unable to make Online Menu: %v", err)
return
}
}
ui.AddChild(&sm)
return nil
}
示例15: chooserFromFile
func chooserFromFile(gp *GamePanel) lua.GoFunction {
return func(L *lua.State) int {
if !LuaCheckParamsOk(L, "ChooserFromFile", LuaString) {
return 0
}
gp.script.syncStart()
defer gp.script.syncEnd()
path := filepath.Join(base.GetDataDir(), L.ToString(-1))
chooser, done, err := makeChooserFromOptionBasicsFile(path)
if err != nil {
base.Error().Printf("Error making chooser: %v", err)
return 0
}
gp.AnchorBox.AddChild(chooser, gui.Anchor{0.5, 0.5, 0.5, 0.5})
gp.script.syncEnd()
res := <-done
L.NewTable()
for i, s := range res {
L.PushInteger(i + 1)
L.PushString(s)
L.SetTable(-3)
}
gp.script.syncStart()
gp.AnchorBox.RemoveChild(chooser)
return 1
}
}