package object import "fmt" // CommonFlag describe flags applicable to all object classes. type CommonFlag int // String returns the textual representation of the value. func (flag CommonFlag) String() string { if int(flag) >= len(commonFlagNames) { return fmt.Sprintf("Unknown 0x%04X", int(flag)) } return commonFlagNames[flag] } func (flag CommonFlag) mask() CommonFlagField { return CommonFlagField(1<> commonFlagLightTypeShift) } // WithLightType returns a new flag field value with given light type set. func (field CommonFlagField) WithLightType(value LightType) CommonFlagField { return CommonFlagField((uint16(field) & ^uint16(commonFlagLightTypeMask)) | ((uint16(value) << commonFlagLightTypeShift) & commonFlagLightTypeMask)) } // UseMode returns the stored enumeration value. func (field CommonFlagField) UseMode() UseMode { return UseMode((field & commonFlagUseModeMask) >> commonFlagUseModeShift) } // WithUseMode returns a new flag field value with given use mode set. func (field CommonFlagField) WithUseMode(value UseMode) CommonFlagField { return CommonFlagField((uint16(field) & ^uint16(commonFlagUseModeMask)) | ((uint16(value) << commonFlagUseModeShift) & commonFlagUseModeMask)) } // LightType describes how an object is affected by lighting. type LightType byte // String returns the textual representation of the value. func (mode LightType) String() string { if int(mode) >= len(lightTypeNames) { return fmt.Sprintf("Unknown 0x%02X", int(mode)) } return lightTypeNames[mode] } // LightType constants. const ( LightTypeSimple LightType = 0x00 LightTypeComplex LightType = 0x01 LightTypeIgnore LightType = 0x02 LightTypeDeferred LightType = 0x03 ) var lightTypeNames = []string{"Simple", "Complex", "Ignore", "Deferred"} // LightTypes returns all known constants. func LightTypes() []LightType { return []LightType{LightTypeSimple, LightTypeComplex, LightTypeIgnore, LightTypeDeferred} } // UseMode describes how an object can be interacted with. type UseMode byte // String returns the textual representation of the value. func (mode UseMode) String() string { if int(mode) >= len(useModeNames) { return fmt.Sprintf("Unknown 0x%02X", int(mode)) } return useModeNames[mode] } // UseMode constants. const ( UseModePickup UseMode = 0x00 UseModeUse UseMode = 0x01 UseModeNull UseMode = 0x03 ) var useModeNames = []string{"Pickup", "Use", "Unknown 0x02", "Null"} // UseModes returns all known constants. func UseModes() []UseMode { return []UseMode{UseModePickup, UseModeUse, UseModeNull} }