Esempio n. 1
0
func MakeHouseFromName(name string) *HouseDef {
	var idiot iamanidiotcontainer
	idiot.Defname = name
	base.GetObject("houses", &idiot)
	idiot.HouseDef.setDoorsOpened(false)
	return idiot.HouseDef
}
Esempio n. 2
0
func (he *HouseEditor) Reload() {
	for _, floor := range he.house.Floors {
		for i := range floor.Rooms {
			base.GetObject("rooms", floor.Rooms[i])
		}
	}
	for _, tab := range he.widgets {
		tab.Reload()
	}
}
Esempio n. 3
0
func registerInteracts() map[string]func() game.Action {
	interact_actions := make(map[string]*InteractDef)
	base.RemoveRegistry("actions-interact_actions")
	base.RegisterRegistry("actions-interact_actions", interact_actions)
	base.RegisterAllObjectsInDir("actions-interact_actions", filepath.Join(base.GetDataDir(), "actions", "interacts"), ".json", "json")
	makers := make(map[string]func() game.Action)
	for name := range interact_actions {
		cname := name
		makers[cname] = func() game.Action {
			a := Interact{Defname: cname}
			base.GetObject("actions-interact_actions", &a)
			return &a
		}
	}
	return makers
}
Esempio n. 4
0
func registerMoves() map[string]func() game.Action {
	move_actions := make(map[string]*MoveDef)
	base.RemoveRegistry("actions-move_actions")
	base.RegisterRegistry("actions-move_actions", move_actions)
	base.RegisterAllObjectsInDir("actions-move_actions", filepath.Join(base.GetDataDir(), "actions", "movement"), ".json", "json")
	makers := make(map[string]func() game.Action)
	for name := range move_actions {
		cname := name
		makers[cname] = func() game.Action {
			a := Move{Defname: cname}
			base.GetObject("actions-move_actions", &a)
			return &a
		}
	}
	return makers
}
Esempio n. 5
0
func registerBasicConditions() {
	registry_name := "conditions-basic_conditions"
	base.RemoveRegistry(registry_name)
	base.RegisterRegistry(registry_name, make(map[string]*BasicConditionDef))
	base.RegisterAllObjectsInDir(registry_name, filepath.Join(base.GetDataDir(), "conditions", "basic_conditions"), ".json", "json")
	names := base.GetAllNamesInRegistry(registry_name)
	for _, name := range names {
		cname := name
		f := func() Condition {
			c := BasicCondition{Defname: cname}
			base.GetObject(registry_name, &c)
			return &c
		}
		condition_makers[name] = f
	}
}
Esempio n. 6
0
func registerSummonActions() map[string]func() game.Action {
	summons_actions := make(map[string]*SummonActionDef)
	base.RemoveRegistry("actions-summons_actions")
	base.RegisterRegistry("actions-summons_actions", summons_actions)
	base.RegisterAllObjectsInDir("actions-summons_actions", filepath.Join(base.GetDataDir(), "actions", "summons"), ".json", "json")
	makers := make(map[string]func() game.Action)
	for name := range summons_actions {
		cname := name
		makers[cname] = func() game.Action {
			a := SummonAction{Defname: cname}
			base.GetObject("actions-summons_actions", &a)
			if a.Ammo > 0 {
				a.Current_ammo = a.Ammo
			} else {
				a.Current_ammo = -1
			}
			return &a
		}
	}
	return makers
}
Esempio n. 7
0
func (e *Entity) SetGear(gear_name string) bool {
	if e.ExplorerEnt == nil {
		base.Error().Printf("Tried to set gear on a non-explorer entity.")
		return false
	}
	if e.ExplorerEnt.Gear != nil && gear_name != "" {
		base.Error().Printf("Tried to set gear on an explorer that already had gear.")
		return false
	}
	if e.ExplorerEnt.Gear == nil && gear_name == "" {
		base.Error().Printf("Tried to remove gear from an explorer with no gear.")
		return false
	}
	if gear_name == "" {
		algorithm.Choose2(&e.Actions, func(a Action) bool {
			return a.String() != e.ExplorerEnt.Gear.Action
		})
		if e.ExplorerEnt.Gear.Condition != "" {
			e.Stats.RemoveCondition(e.ExplorerEnt.Gear.Condition)
		}
		e.ExplorerEnt.Gear = nil
		return true
	}
	var g Gear
	g.Defname = gear_name
	base.GetObject("gear", &g)
	if g.Name == "" {
		base.Error().Printf("Tried to load gear '%s' that doesn't exist.", gear_name)
		return false
	}
	e.ExplorerEnt.Gear = &g
	if g.Action != "" {
		e.Actions = append(e.Actions, MakeAction(g.Action))
	}
	if g.Condition != "" {
		e.Stats.ApplyCondition(status.MakeCondition(g.Condition))
	}
	return true
}
Esempio n. 8
0
func makeHouseDataTab(house *HouseDef, viewer *HouseViewer) *houseDataTab {
	var hdt houseDataTab
	hdt.VerticalTable = gui.MakeVerticalTable()
	hdt.house = house
	hdt.viewer = viewer

	hdt.name = gui.MakeTextEditLine("standard", "name", 300, 1, 1, 1, 1)
	num_floors_options := []string{"1 Floor", "2 Floors", "3 Floors", "4 Floors"}
	hdt.num_floors = gui.MakeComboTextBox(num_floors_options, 300)
	if hdt.house.Icon.Path == "" {
		hdt.house.Icon.Path = base.Path(filepath.Join(datadir, "houses", "icons"))
	}
	hdt.icon = gui.MakeFileWidget(string(hdt.house.Icon.Path), imagePathFilter)

	hdt.VerticalTable.AddChild(hdt.name)
	hdt.VerticalTable.AddChild(hdt.num_floors)
	hdt.VerticalTable.AddChild(hdt.icon)

	names := GetAllRoomNames()
	room_buttons := gui.MakeVerticalTable()
	for _, name := range names {
		n := name
		room_buttons.AddChild(gui.MakeButton("standard", name, 300, 1, 1, 1, 1, func(int64) {
			if hdt.temp_room != nil {
				return
			}
			hdt.temp_room = &Room{Defname: n}
			base.GetObject("rooms", hdt.temp_room)
			hdt.temp_room.temporary = true
			hdt.temp_room.invalid = true
			hdt.house.Floors[0].Rooms = append(hdt.house.Floors[0].Rooms, hdt.temp_room)
			hdt.drag_anchor.x = float32(hdt.temp_room.Size.Dx / 2)
			hdt.drag_anchor.y = float32(hdt.temp_room.Size.Dy / 2)
		}))
	}
	scroller := gui.MakeScrollFrame(room_buttons, 300, 700)
	hdt.VerticalTable.AddChild(scroller)
	return &hdt
}
Esempio n. 9
0
func MakeEntity(name string, g *Game) *Entity {
	ent := Entity{Defname: name}
	base.GetObject("entities", &ent)

	for _, action_name := range ent.Action_names {
		ent.Actions = append(ent.Actions, MakeAction(action_name))
	}

	if ent.Side() == SideHaunt || ent.Side() == SideExplorers {
		stats := status.MakeInst(ent.Base)
		stats.OnBegin()
		ent.Stats = &stats
	}

	ent.Info = makeInfo()

	ent.Id = g.Entity_id
	g.Entity_id++

	ent.Load(g)
	g.all_ents_in_memory[&ent] = true

	return &ent
}
Esempio n. 10
0
func (wt *WallTexture) Load() {
	base.GetObject("wall_textures", wt)
}
Esempio n. 11
0
func MakeGear(name string) *Gear {
	g := Gear{Defname: name}
	base.GetObject("gear", &g)
	return &g
}
Esempio n. 12
0
func (d *Door) Load() {
	base.GetObject("doors", d)
}
Esempio n. 13
0
// Pushes an entity onto the stack, it is a table containing the following:
// e.id -> EntityId of this entity
// e.name -> Name as displayed to the user
// e.gear_options -> Table mapping gear to icon for all available gear
// e.gear -> Name of the selected gear, nil if none is selected
// e.actions -> Array of actions this entity has available
func LuaPushEntity(L *lua.State, ent *Entity) {
	if ent == nil {
		L.PushNil()
		return
	}
	// id and Name can be added to the ent table as static data since they
	// never change.
	L.NewTable()
	L.PushString("Name")
	L.PushString(ent.Name)
	L.SetTable(-3)
	L.PushString("id")
	L.PushInteger(int(ent.Id))
	L.SetTable(-3)
	L.PushString("type")
	L.PushString("Entity")
	L.SetTable(-3)

	// Meta table for the Entity so that any dynamic data is generated
	// on-the-fly
	LuaPushSmartFunctionTable(L, FunctionTable{
		"Conditions": func() {
			L.NewTable()
			for _, condition := range ent.Stats.ConditionNames() {
				L.PushString(condition)
				L.PushBoolean(true)
				L.SetTable(-3)
			}
		},
		"Side": func() {
			L.NewTable()
			sides := map[string]Side{
				"Denizen":  SideHaunt,
				"Intruder": SideExplorers,
				"Npc":      SideNpc,
				"Object":   SideObject,
			}
			for str, side := range sides {
				L.PushString(str)
				L.PushBoolean(ent.Side() == side)
				L.SetTable(-3)
			}
		},
		"State": func() {
			L.PushString(ent.Sprite().State())
		},
		"Master": func() {
			L.NewTable()
			for key, val := range ent.Ai_data {
				L.PushString(key)
				L.PushString(val)
				L.SetTable(-3)
			}
		},
		"GearOptions": func() {
			L.NewTable()
			if ent.ExplorerEnt != nil {
				for _, gear_name := range ent.ExplorerEnt.Gear_names {
					var g Gear
					g.Defname = gear_name
					base.GetObject("gear", &g)
					L.PushString(gear_name)
					L.PushString(g.Large_icon.Path.String())
					L.SetTable(-3)
				}
			}
		},
		"Gear": func() {
			if ent.ExplorerEnt != nil && ent.ExplorerEnt.Gear != nil {
				L.PushString(ent.ExplorerEnt.Gear.Name)
			} else {
				L.PushNil()
			}
		},
		"Actions": func() {
			L.NewTable()
			for _, action := range ent.Actions {
				L.PushString(action.String())
				action.Push(L)
				L.SetTable(-3)
			}
		},
		"Pos": func() {
			x, y := ent.Pos()
			LuaPushPoint(L, x, y)
		},
		"Corpus": func() {
			L.PushInteger(ent.Stats.Corpus())
		},
		"Ego": func() {
			L.PushInteger(ent.Stats.Ego())
		},
		"HpCur": func() {
			L.PushInteger(ent.Stats.HpCur())
		},
		"HpMax": func() {
			L.PushInteger(ent.Stats.HpMax())
		},
		"ApCur": func() {
			L.PushInteger(ent.Stats.ApCur())
		},
		"ApMax": func() {
			L.PushInteger(ent.Stats.ApMax())
		},
		"Info": func() {
			L.NewTable()
			L.PushString("LastEntityThatIAttacked")
			LuaPushEntity(L, ent.Game().EntityById(ent.Info.LastEntThatIAttacked))
			L.SetTable(-3)
			L.PushString("LastEntThatAttackedMe")
			LuaPushEntity(L, ent.Game().EntityById(ent.Info.LastEntThatAttackedMe))
			L.SetTable(-3)
		},
	})
	L.SetMetaTable(-2)
}
Esempio n. 14
0
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
}
Esempio n. 15
0
func MakeEntityPlacer(game *Game, roster_names []string, roster_costs []int, min, max int, pattern string) (*EntityPlacer, <-chan []*Entity, error) {
	var ep EntityPlacer
	err := base.LoadAndProcessObject(filepath.Join(base.GetDataDir(), "ui", "entity_placer", "config.json"), "json", &ep.layout)
	if err != nil {
		return nil, nil, err
	}
	if len(roster_names) != len(roster_costs) {
		return nil, nil, errors.New("Must have as many names as costs.")
	}
	if len(roster_names) <= 0 || len(roster_names) > ep.layout.Roster.Max_options {
		return nil, nil, errors.New(fmt.Sprintf("Can't have more than %d ents in a roster.", ep.layout.Roster.Max_options))
	}

	ep.layout.Undo.valid_func = func() bool {
		return len(ep.ents) > 0
	}
	ep.layout.Undo.f = func(interface{}) {
		ent := ep.ents[len(ep.ents)-1]
		ep.points += ep.roster[ent.Name]
		ep.ents = ep.ents[0 : len(ep.ents)-1]
		algorithm.Choose2(&game.Ents, func(e *Entity) bool { return e != ent })
		game.viewer.RemoveDrawable(ent)
	}

	ep.layout.Done.valid_func = func() bool {
		return ep.points >= 0 && min <= (max-ep.points)
	}
	done := make(chan []*Entity)
	ep.layout.Done.f = func(interface{}) {
		done <- ep.ents
		close(done)
		house.PopSpawnRegexp()
		game.viewer.RemoveDrawable(game.new_ent)
		game.new_ent = nil
	}
	ep.roster_names = roster_names
	ep.roster = make(map[string]int)
	for i, name := range ep.roster_names {
		ep.roster[name] = roster_costs[i]
	}
	ep.game = game
	ep.show_points = !(min == 1 && max == 1)
	ep.points = max
	ep.pattern = pattern
	house.PushSpawnRegexp(ep.pattern)
	x := ep.layout.Roster.X
	for _, name := range ep.roster_names {
		var b Button
		b.X = x
		x += (ep.layout.Roster.X2 - ep.layout.Roster.X) / (ep.layout.Roster.Max_options - 1)
		b.Y = ep.layout.Roster.Y
		ent := Entity{Defname: name}
		base.GetObject("entities", &ent)
		b.Texture = ent.Still
		cost := ep.roster[name]
		b.valid_func = func() bool {
			return ep.points >= cost
		}
		b.f = func(interface{}) {
			ep.game.viewer.RemoveDrawable(ep.game.new_ent)
			ep.game.new_ent = MakeEntity(ent.Name, ep.game)
			ep.game.viewer.AddDrawable(ep.game.new_ent)
		}
		ep.ent_buttons = append(ep.ent_buttons, &b)
	}

	ep.buttons = []*Button{
		&ep.layout.Undo,
		&ep.layout.Done,
	}
	for _, b := range ep.ent_buttons {
		ep.buttons = append(ep.buttons, b)
	}

	return &ep, done, nil
}
Esempio n. 16
0
func MakeFurniture(name string) *Furniture {
	f := Furniture{Defname: name}
	base.GetObject("furniture", &f)
	return &f
}
Esempio n. 17
0
func MakeDoor(name string) *Door {
	d := Door{Defname: name}
	base.GetObject("doors", &d)
	return &d
}