示例#1
0
文件: los.go 项目: FlyingCar/haunts
func makeGame(h *house.HouseDef) *Game {
	var g Game
	g.Side = SideExplorers
	g.House = h
	g.House.Normalize()
	g.viewer = house.MakeHouseViewer(g.House, 62)
	g.Rand = cmwc.MakeCmwc(4285415527, 3)
	g.Rand.SeedWithDevRand()

	// This way an unset id will be invalid
	g.Entity_id = 1

	g.Turn = 1
	g.Side = SideHaunt

	g.setup()

	return &g
}
示例#2
0
文件: los.go 项目: FlyingCar/haunts
func (g *Game) GobDecode(data []byte) error {
	g.gameDataPrivate = gameDataPrivate{}
	for ent := range g.all_ents_in_memory {
		ent.Release()
	}
	if g.Ai.intruders != nil {
		g.Ai.intruders.Terminate()
	}
	if g.Ai.minions != nil {
		g.Ai.minions.Terminate()
	}
	if g.Ai.denizens != nil {
		g.Ai.denizens.Terminate()
	}

	g.gameDataGobbable = gameDataGobbable{}

	dec := gob.NewDecoder(bytes.NewBuffer(data))
	if err := dec.Decode(&g.gameDataGobbable); err != nil {
		return err
	}

	base.ProcessObject(reflect.ValueOf(g.House), "")
	g.House.Normalize()
	g.viewer = house.MakeHouseViewer(g.House, 62)
	g.viewer.Edit_mode = true
	for _, ent := range g.Ents {
		base.GetObject("entities", ent)
	}
	g.setup()
	for _, ent := range g.Ents {
		ent.Load(g)
	}
	var sss []sprite.SpriteState
	if err := dec.Decode(&sss); err != nil {
		return err
	}
	if len(sss) != len(g.Ents) {
		return errors.New("SpriteStates were not recorded properly.")
	}
	for i := range sss {
		g.Ents[i].Sprite().SetSpriteState(sss[i])
	}

	// If Ais were bound then their paths will be listed here and we have to
	// reload them
	if g.Ai.Path.Denizens != "" {
		ai_maker(g.Ai.Path.Denizens, g, nil, &g.Ai.denizens, DenizensAi)
	}
	if g.Ai.denizens == nil {
		g.Ai.denizens = inactiveAi{}
	}
	if g.Ai.Path.Intruders != "" {
		ai_maker(g.Ai.Path.Intruders, g, nil, &g.Ai.intruders, IntrudersAi)
	}
	if g.Ai.intruders == nil {
		g.Ai.intruders = inactiveAi{}
	}
	if g.Ai.Path.Minions != "" {
		ai_maker(g.Ai.Path.Minions, g, nil, &g.Ai.minions, MinionsAi)
	}
	if g.Ai.minions == nil {
		g.Ai.minions = inactiveAi{}
	}

	return nil
}