internal void Update() { if (!_gameObject.Definition.WeaponSets.TryGetValue(_gameObject.WeaponSetConditions, out var weaponTemplateSet)) { return; } if (_currentWeaponTemplateSet == weaponTemplateSet) { return; } _currentWeaponTemplateSet = weaponTemplateSet; _currentWeaponSlot = WeaponSlot.Primary; _filledWeaponSlots = 0; _combinedAntiMask = WeaponAntiFlags.None; for (var i = 0; i < _weapons.Length; i++) { var weaponTemplate = _currentWeaponTemplateSet.Slots[i]?.Weapon.Value; if (weaponTemplate != null) { _weapons[i] = new Weapon(_gameObject, weaponTemplate, (WeaponSlot)i, _gameObject.GameContext); _filledWeaponSlots |= (uint)(1 << i); _combinedAntiMask |= weaponTemplate.AntiMask; } } }
public void Persist(StatePersister reader) { reader.PersistVersion(1); var objectDefinitionName = _currentWeaponTemplateSet?.ObjectDefinition.Name; reader.PersistAsciiString(ref objectDefinitionName); var conditions = _currentWeaponTemplateSet?.Conditions ?? new BitArray <WeaponSetConditions>(); reader.PersistBitArray(ref conditions); if (reader.Mode == StatePersistMode.Read) { _currentWeaponTemplateSet = _gameObject.Definition.WeaponSets[conditions]; } // In Generals there are 3 possible weapons. // Later games have up to 5. reader.BeginArray("Weapons"); for (var i = 0; i < 3; i++) { reader.BeginObject(); var slotFilled = _weapons[i] != null; reader.PersistBoolean(ref slotFilled); if (slotFilled) { if (reader.Mode == StatePersistMode.Read) { _weapons[i] = new Weapon( _gameObject, _currentWeaponTemplateSet.Slots[i].Weapon.Value, (WeaponSlot)i, _gameObject.GameContext); } reader.PersistObject(_weapons[i], "Value"); } else { _weapons[i] = null; } reader.EndObject(); } reader.EndArray(); reader.PersistEnum(ref _currentWeaponSlot); reader.PersistUInt32(ref _unknown1); reader.PersistUInt32(ref _filledWeaponSlots); reader.PersistEnumFlags(ref _combinedAntiMask); reader.PersistUInt32(ref _unknown2); reader.PersistBoolean(ref _unknown3); reader.PersistBoolean(ref _unknown4); }
internal void Load(SaveFileReader reader) { reader.ReadVersion(1); // This is the object definition which defined the WeaponSet // (either a normal object or DefaultThingTemplate) var objectDefinitionName = reader.ReadAsciiString(); var conditions = reader.ReadBitArray <WeaponSetConditions>(); _currentWeaponTemplateSet = _gameObject.Definition.WeaponSets[conditions]; // In Generals there are 3 possible weapons. // Later games have up to 5. for (var i = 0; i < 3; i++) { var slotFilled = reader.ReadBoolean(); if (slotFilled) { _weapons[i] = new Weapon(_gameObject, _currentWeaponTemplateSet.Slots[i].Weapon.Value, (WeaponSlot)i, _gameObject.GameContext); _weapons[i].Load(reader); } else { _weapons[i] = null; } } _currentWeaponSlot = reader.ReadEnum <WeaponSlot>(); var unknown2 = reader.ReadUInt32(); _filledWeaponSlots = reader.ReadUInt32(); _combinedAntiMask = reader.ReadEnumFlags <WeaponAntiFlags>(); var unknown5 = reader.ReadUInt32(); var unknownBool1 = reader.ReadBoolean(); var unknownBool2 = reader.ReadBoolean(); }