// Objects is a debug function to generate objects. func Objects(a *area.Area, num int) { o := make(map[coord.Coord]area.DrawPather, a.Width*a.Height) log.Println(len(object.Objects)) var objectList = make([]object.Object, len(object.Objects)) var index int for _, o := range object.Objects { objectList[index] = o index++ } for x := 0; x < a.Width; x++ { for y := 0; y < a.Height; y++ { if num <= 0 { return } if util.RandInt(0, 50) != 42 { continue } if !a.IsXYPathable(x, y) { continue } c := coord.Coord{X: x, Y: y} o[c] = objectList[util.RandInt(0, len(objectList))].New() } } a.Objects = o }
func (c *Creature) FOV(a *area.Area) (cs map[coord.Coord]struct{}) { radius := c.Sight cs = make(map[coord.Coord]struct{}) for x := c.X() - radius; x <= c.X()+radius; x++ { for y := c.Y() - radius; y <= c.Y()+radius; y++ { // Distance between creature x and y coordinates and sight radius. dx := float64(x - c.X()) dy := float64(y - c.Y()) // Distance between creature and sight radius. dist := math.Sqrt(math.Pow(dx, 2) + math.Pow(dy, 2)) // Discriminate coordinates which are outside of the circle. if dist > float64(radius) { continue } // Ignore hero. for _, p := range get_line(c.X(), c.Y(), x, y)[1:] { if !a.ExistsXY(p.X, p.Y) { break } cs[p] = struct{}{} // Terrain that breaks line of sight. if !a.IsXYPathable(p.X, p.Y) { break } } } } return cs }
// Mobs is a debug function to add mobs to the map. func Mobs(a *area.Area, num int) { var mobList = []creature.Creature{ // creature.Beastiary["echidna"], creature.Beastiary["gobbal"], creature.Beastiary["tofu"], creature.Beastiary["iop"], creature.Beastiary["arachnee"], } for x := 0; x < a.Width; x++ { for y := 0; y < a.Height; y++ { if num <= 0 { return } if util.RandInt(0, 50) != 42 { continue } if !a.IsXYPathable(x, y) { continue } g := mobList[util.RandInt(0, len(mobList))] g.Inventory = make(creature.Inventory) c := coord.Coord{X: x, Y: y} g.SetX(x) g.SetY(y) a.Monsters[c] = &g num-- } } }
// Items is a debug function to add mobs to the map. func Items(a *area.Area, num int) { var itemList = make([]item.DrawItemer, len(item.Items)) var index int for _, i := range item.Items { itemList[index] = i index++ } for x := 0; x < a.Width; x++ { for y := 0; y < a.Height; y++ { if num <= 0 { return } if util.RandInt(0, 50) != 42 { continue } if !a.IsXYPathable(x, y) { continue } c := coord.Coord{x, y} i := item.New(itemList[util.RandInt(0, len(itemList))]) if i == nil { continue } i.SetX(x) i.SetY(y) if a.Items[c] == nil { a.Items[c] = new(area.Stack) } a.Items[c].Push(i) num-- } } }