當前位置: 首頁>>代碼示例>>Golang>>正文


Golang base.Error函數代碼示例

本文整理匯總了Golang中github.com/MobRulesGames/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
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:33,代碼來源:move.go

示例2: 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:genbattle,項目名稱:haunts,代碼行數:32,代碼來源:ui_versus.go

示例3: 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
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:57,代碼來源:aoe_attack.go

示例4: Maintain

func (a *BasicAttack) Maintain(dt int64, g *game.Game, ae game.ActionExec) game.MaintenanceStatus {
	if ae != nil {
		a.exec = ae.(*basicAttackExec)
		a.ent = g.EntityById(ae.EntityId())
		a.target = a.ent.Game().EntityById(a.exec.Target)

		// Track this information for the ais
		if a.ent.Side() != a.target.Side() {
			a.ent.Info.LastEntThatIAttacked = a.target.Id
			a.target.Info.LastEntThatAttackedMe = a.ent.Id
		}

		if a.Ap > a.ent.Stats.ApCur() {
			base.Error().Printf("Got a basic attack that required more ap than available: %v", a.exec)
			base.Error().Printf("Ent: %s, Ap: %d", a.ent.Name, a.ent.Stats.ApCur())
			return game.Complete
		}

		if !a.validTarget(a.ent, a.target) {
			base.Error().Printf("Got a basic attack that was invalid for some reason: %v", a.exec)
			return game.Complete
		}
	}
	if a.ent.Sprite().State() == "ready" && a.target.Sprite().State() == "ready" {
		a.target.TurnToFace(a.ent.Pos())
		a.ent.TurnToFace(a.target.Pos())
		if a.Current_ammo > 0 {
			a.Current_ammo--
		}
		a.ent.Stats.ApplyDamage(-a.Ap, 0, status.Unspecified)
		var defender_cmds []string
		if g.DoAttack(a.ent, a.target, a.Strength, a.Kind) {
			for _, name := range a.Conditions {
				a.target.Stats.ApplyCondition(status.MakeCondition(name))
			}
			a.target.Stats.ApplyDamage(0, -a.Damage, a.Kind)
			if a.target.Stats.HpCur() <= 0 {
				defender_cmds = []string{"defend", "killed"}
			} else {
				defender_cmds = []string{"defend", "damaged"}
			}
			results[a.exec.id] = BasicAttackResult{Hit: true}
		} else {
			defender_cmds = []string{"defend", "undamaged"}
			results[a.exec.id] = BasicAttackResult{Hit: false}
		}
		sprites := []*sprite.Sprite{a.ent.Sprite(), a.target.Sprite()}
		sprite.CommandSync(sprites, [][]string{[]string{a.Animation}, defender_cmds}, "hit")
		return game.Complete
	}
	return game.InProgress
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:52,代碼來源:basic_attack.go

示例5: Draw

func (mdb *MediumDialogBox) Draw(region gui.Region) {
	mdb.region = region
	if mdb.done {
		return
	}
	gl.Enable(gl.TEXTURE_2D)
	gl.Color4ub(255, 255, 255, 255)
	mdb.layout.Background.Data().RenderNatural(region.X, region.Y)
	for _, button := range mdb.buttons {
		button.RenderAt(region.X, region.Y)
	}

	for i := range mdb.format.Sections {
		section := mdb.format.Sections[i]
		data := mdb.data.Pages[mdb.data.cur_page].Sections[i]
		p := section.Paragraph
		d := base.GetDictionary(p.Size)
		var just gui.Justification
		switch p.Halign {
		case "left":
			just = gui.Left
		case "right":
			just = gui.Right
		case "center":
			just = gui.Center
		default:
			base.Error().Printf("Unknown justification '%s'", p.Halign)
			p.Halign = "left"
		}
		var valign gui.Justification
		switch p.Valign {
		case "top":
			valign = gui.Top
		case "bottom":
			valign = gui.Bottom
		case "center":
			valign = gui.Center
		default:
			base.Error().Printf("Unknown justification '%s'", p.Valign)
			p.Valign = "top"
		}
		gl.Color4ub(255, 255, 255, 255)

		d.RenderParagraph(data.Text, float64(p.X+region.X), float64(p.Y+region.Y)-d.MaxHeight()/2, 0, float64(p.Dx), d.MaxHeight(), just, valign)

		gl.Color4ub(255, 255, 255, byte(data.shading*255))
		tex := data.Image.Data()
		tex.RenderNatural(region.X+section.X-tex.Dx()/2, region.Y+section.Y-tex.Dy()/2)
	}
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:50,代碼來源:ui_dialog.go

示例6: 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
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:25,代碼來源:summon.go

示例7: 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]
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:7,代碼來源:spawn.go

示例8: 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.PushGoFunction(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)
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:35,代碼來源:script_utils.go

示例9: 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()
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:7,代碼來源:action.go

示例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
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:33,代碼來源:ai.go

示例11: 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.Credits,
		&sm.layout.Menu.Versus,
		&sm.layout.Menu.Online,
		&sm.layout.Menu.Settings,
	}
	sm.layout.Menu.Credits.f = func(interface{}) {
		ui.RemoveChild(&sm)
		err := InsertCreditsMenu(ui)
		if err != nil {
			base.Error().Printf("Unable to make Credits Menu: %v", err)
			return
		}
	}
	sm.layout.Menu.Versus.f = func(interface{}) {
		ui.RemoveChild(&sm)
		err := InsertMapChooser(
			ui,
			func(name string) {
				ui.AddChild(MakeGamePanel(name, nil, nil, ""))
			},
			InsertStartMenu,
		)
		if err != nil {
			base.Error().Printf("Unable to make Map Chooser: %v", err)
			return
		}
	}
	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
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:47,代碼來源:ui_start.go

示例12: MakeCondition

func MakeCondition(name string) Condition {
	maker, ok := condition_makers[name]
	if !ok {
		base.Error().Printf("Unable to find a Condition named '%s'", name)
		return condition_makers["Error"]()
	}
	return maker()
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:8,代碼來源:conditions.go

示例13: Dims

func (ei *entityDef) Dims() (int, int) {
	if ei.Dx <= 0 || ei.Dy <= 0 {
		base.Error().Printf("Entity '%s' didn't have its Dims set properly", ei.Name)
		ei.Dx = 1
		ei.Dy = 1
	}
	return ei.Dx, ei.Dy
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:8,代碼來源:entity.go

示例14: encodeActionExec

func encodeActionExec(ae ActionExec) []byte {
	b := bytes.NewBuffer(nil)
	enc := gob.NewEncoder(b)
	err := enc.Encode(ae)
	if err != nil {
		base.Error().Printf("Failed to gob an ActionExec: %v", err)
		return nil
	}
	return b.Bytes()
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:10,代碼來源:action.go

示例15: decodeActionExec

func decodeActionExec(b []byte) ActionExec {
	var ae ActionExec
	dec := gob.NewDecoder(bytes.NewReader(b))
	err := dec.Decode(&ae)
	if err != nil {
		base.Error().Printf("Failed to ungob an ActionExec: %v", err)
		return nil
	}
	return ae
}
開發者ID:genbattle,項目名稱:haunts,代碼行數:10,代碼來源:action.go


注:本文中的github.com/MobRulesGames/haunts/base.Error函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。