Example #1
0
        /// <summary>
        /// Picks up a weapon and places it into an empty slot, if available.
        /// </summary>
        /// <param name="weapon">The weapon to pick up.</param>
        /// <returns>true if the weapon was picked up successfully.</returns>
        public bool PickUpWeapon(WeaponObject weapon)
        {
            if (weapon != null && _weapons.Count < 4)
            {
                PickUp(weapon);
                if (_backupWeaponIndex >= 0)
                {
                    _weapons.Insert(_backupWeaponIndex, weapon);
                }
                else
                {
                    _weapons.Add(weapon);
                }

                _backupWeaponIndex++;
                if (Carrier == null || Carrier.TagGroup != TagGroup.Vehi)
                {
                    _currentWeaponIndex++;
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        public override void ReplaceWith(GameObject newObj)
        {
            GameObject user = _user;

            if (Carrier == null && _user != null)
            {
                ReplaceUsedObject(_user, this, newObj);
            }

            WeaponObject newWeapon = newObj as WeaponObject;

            if (newWeapon != null)
            {
                newWeapon._weaponFlags = _weaponFlags;
            }

            base.ReplaceWith(newObj);

            if (newWeapon != null)
            {
                newWeapon._user = user;
                _user           = null;
            }

            newWeapon._usageInfo = _usageInfo;
        }
Example #3
0
        /// <summary>
        /// Changes one of the weapons that this object is holding.
        /// </summary>
        /// <remarks>
        /// If index is larger than the current weapon count, the weapon will be placed into the first free slot.
        /// </remarks>
        /// <param name="index">The zero-based weapon index (0 = 1st weapon, 3 = 4th weapon)</param>
        /// <param name="newWeapon">The new weapon, or null for none.</param>
        public void ChangeWeapon(int index, WeaponObject newWeapon)
        {
            if (index < 0 || index >= 4)
            {
                throw new IndexOutOfRangeException("Trying to change a non-existant weapon slot");
            }

            if (index >= _weapons.Count || _backupWeaponIndex < 0)
            {
                // No slot available - just pick it up
                if (newWeapon != null)
                {
                    PickUpWeapon(newWeapon);
                }
                return;
            }

            if (newWeapon != null)
            {
                int listIndex = TranslateIndex(index);
                _weapons[listIndex].ReplaceWith(newWeapon);
                _weapons[listIndex] = newWeapon;
            }
            else
            {
                DropWeapon(index);
            }
        }
Example #4
0
 public void DropWeapon(int index)
 {
     if (index >= 0 && index < _weapons.Count && _backupWeaponIndex >= 0)
     {
         WeaponObject weapon = _weapons[TranslateIndex(index)];
         weapon.Drop();
     }
 }
Example #5
0
        private bool ProcessObjectEntry(SaveIO.SaveReader reader, bool active, uint datumIndex, ushort flags, uint size, long offset)
        {
            if (!active)
            {
                _objects.Add(null);
                return(true);
            }

            // Read the object entry
            ObjectEntry entry = new ObjectEntry(_objectChunk, reader, datumIndex, flags, offset);

            // Seek to the start of the object data
            reader.Seek(_objectPoolStart + entry.PoolOffset, SeekOrigin.Begin);

            // Process it based on object class
            GameObject obj;

            switch (entry.TagGroup)
            {
            case TagGroup.Bipd:
                obj = new BipedObject(reader, entry);
                break;

            case TagGroup.Vehi:
                obj = new VehicleObject(reader, entry);
                break;

            case TagGroup.Weap:
                obj = new WeaponObject(reader, entry);
                break;

            case TagGroup.Eqip:
                obj = new EquipmentObject(reader, entry);
                break;

            default:
                obj = new GameObject(reader, entry);
                break;
            }
            _objects.Add(obj);

            if (obj.Next == null)
            {
                _lastPoolObject = obj;
            }

            return(true);
        }