// NewGameObjects returns a new instance of GameObjects.
func NewGameObjects(library io.StoreLibrary) (gameObjects *GameObjects, err error) {
	var cybstrng [model.LanguageCount]chunk.Store
	var objart chunk.Store
	var objProperties objprop.Store

	if err == nil {
		objart, err = library.ChunkStore("objart.res")
	}
	if err == nil {
		objProperties, err = library.ObjpropStore("objprop.dat")
	}
	for i := 0; i < model.LanguageCount && err == nil; i++ {
		cybstrng[i], err = library.ChunkStore(localized[i].cybstrng)
	}
	if err == nil {
		gameObjects = &GameObjects{
			cybstrng:       cybstrng,
			cp:             text.DefaultCodepage(),
			desc:           objprop.StandardProperties(),
			objProperties:  objProperties,
			objart:         objart,
			objIconOffsets: make(map[res.ObjectID]int),
			mapIconOffsets: make(map[res.ObjectID]int)}

		offset := 1
		for classIndex, classDesc := range gameObjects.desc {
			for subclassIndex, subclassDesc := range classDesc.Subclasses {
				for typeIndex := uint32(0); typeIndex < subclassDesc.TypeCount; typeIndex++ {
					objID := res.MakeObjectID(res.ObjectClass(classIndex), res.ObjectSubclass(subclassIndex), res.ObjectType(typeIndex))
					commonProperties := gameObjects.commonProperties(objID)
					extraImages := int(commonProperties.Extra >> 4)

					gameObjects.objIconOffsets[objID] = offset
					offset = offset + 3 + extraImages
					gameObjects.mapIconOffsets[objID] = offset - 1
				}
			}
		}
	}

	return
}