/
building.go
118 lines (108 loc) · 2.8 KB
/
building.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package genfurnishing
import (
"log"
"math/rand"
)
// A building is a collection of rooms serving a purpose with a total size and a number of inhabitants with
// a certain social status, profession, and hobbies.
type Building struct {
Name string // Name of the building.
Rooms []*Room // Rooms in the building.
Size int // Size of the building.
}
// BuildingConfig represents a building prototype and all the possible
// variations of rooms that can be found in it.
type BuildingConfig struct {
Name string // Name of the building type.
Required []string // Required rooms
Possible []string // Possible rooms
Size [2]int // Minimum/Maximum size of the building.
}
// NewBuildingConfig returns a new building configuration for generating a specific type of building.
func NewBuildingConfig(name string, required, possible []string, minSize, maxSize int) *BuildingConfig {
return &BuildingConfig{
Name: name,
Required: required,
Possible: possible,
Size: [2]int{minSize, maxSize},
}
}
// Generate a building from the config.
func (bc *BuildingConfig) Generate() *Building {
building := &Building{
Name: bc.Name,
Size: bc.Size[0] + rand.Intn(bc.Size[1]-bc.Size[0]),
}
// Generate all required rooms.
for _, room := range bc.Required {
building.Rooms = append(building.Rooms, roomTypeToConfig[room].Generate())
}
// Generate random rooms.
for _, i := range rand.Perm(len(bc.Possible)) {
room := roomTypeToConfig[bc.Possible[i]].Generate()
building.Rooms = append(building.Rooms, room)
if len(building.Rooms) >= building.Size {
break
}
}
return building
}
// Log the building.
func (b *Building) Log() {
log.Printf("Building: %s", b.Name)
for _, room := range b.Rooms {
room.Log()
}
}
const (
TypeKeep = "Keep"
TypeGreatHouse = "Great House"
// TypeManor = "Manor"
// TypeTownhouse = "Townhouse"
// TypeCottage = "Cottage"
// TypeChurch = "Church"
// TypeTemple = "Temple"
// TypeGuardhouse = "Guardhouse"
// TypeInn = "Inn"
)
var (
BuildingKeep = NewBuildingConfig(TypeKeep, []string{
RoomTypeGreatHall,
RoomTypeKitchen,
RoomTypePantry,
RoomTypeBedroom,
RoomTypeArmory,
RoomTypePrison,
}, []string{
RoomTypeAtrium,
RoomTypeBallroom,
RoomTypeBathhouse,
RoomTypeChamber,
RoomTypeDining,
RoomTypeDormitory,
RoomTypeHallway,
RoomTypeLaboratory,
RoomTypeLibrary,
RoomTypeParlour,
RoomTypeThrone,
RoomTypeTorture,
RoomTypeTreasury,
}, 10, 15)
BuildingGreatHouse = NewBuildingConfig(TypeGreatHouse, []string{
RoomTypeGreatHall,
RoomTypeKitchen,
RoomTypePantry,
RoomTypeBedroom,
}, []string{
RoomTypeArmory,
RoomTypeAtrium,
RoomTypeBallroom,
RoomTypeBathhouse,
RoomTypeChamber,
RoomTypeDining,
RoomTypeDormitory,
RoomTypeHallway,
RoomTypeLaboratory,
RoomTypeLibrary,
}, 6, 12)
)