示例#1
0
        /// <summary>
        /// Sets weapons, this will remove exsisting.
        /// </summary>
        /// <param name="wpns"></param>
        internal void SetWeapons(ComponentInstance[] wpns)
        {
            int count = wpns.Length;

            Guid[] wpnIDs              = new Guid[count];
            int[]  internalMagSizes    = new int[count];
            int[]  internalMagQty      = new int[count];
            int[]  reloadAmountsPerSec = new int[count];
            int[]  amountPerShot       = new int[count];
            int[]  minShotsPerfire     = new int[count];
            //GenericWeaponAtb.WpnTypes[] wpnTypes = new GenericWeaponAtb.WpnTypes[count];
            FireControlAbilityState[] fcStates  = new FireControlAbilityState[count];
            IFireWeaponInstr[]        fireInstr = new IFireWeaponInstr[count];
            double[] launchForce = new double[count];
            ShotsFiredThisTick = new int[count];
            for (int i = 0; i < count; i++)
            {
                GenericWeaponAtb wpnAtb = wpns[i].Design.GetAttribute <GenericWeaponAtb>();
                var wpnState            = wpns[i].GetAbilityState <WeaponState>();

                wpnIDs[i]              = wpns[i].ID;
                internalMagSizes[i]    = wpnAtb.InternalMagSize;
                internalMagQty[i]      = wpnState.InternalMagCurAmount;
                reloadAmountsPerSec[i] = wpnAtb.ReloadAmountPerSec;
                amountPerShot[i]       = wpnAtb.AmountPerShot;
                minShotsPerfire[i]     = wpnAtb.MinShotsPerfire;
                //wpnTypes[i] = wpnAtb.WpnType;
                fcStates[i]  = (FireControlAbilityState)wpnState.ParentState;
                fireInstr[i] = wpnState.FireWeaponInstructions;
                if (wpns[i].Design.HasAttribute <MissileLauncherAtb>())
                {
                    launchForce[i] = wpns[i].Design.GetAttribute <MissileLauncherAtb>().LaunchForce;
                }
                else
                {
                    launchForce[i] = 1;
                }

                ShotsFiredThisTick[i] = 0;
            }

            WpnIDs              = wpnIDs;
            InternalMagSizes    = internalMagSizes;
            InternalMagQty      = internalMagQty;
            ReloadAmountsPerSec = reloadAmountsPerSec;
            AmountPerShot       = amountPerShot;
            MinShotsPerfire     = minShotsPerfire;
            //WpnTypes = wpnTypes;
            FireControlStates = fcStates;
            FireInstructions  = fireInstr;
            LaunchForces      = launchForce;
        }
示例#2
0
        /// <summary>
        /// Adds to exsisting weapons.
        /// not thread safe.
        /// </summary>
        /// <param name="wpns"></param>
        internal void AddWeapons(ComponentInstance[] wpns)
        {
            //first check that the weapons to add don't already exsist in the blob.
            List <ComponentInstance> weaponsToAdd = new List <ComponentInstance>();

            foreach (var wpn in wpns)
            {
                bool add = true;
                foreach (var wpnID in WpnIDs)
                {
                    if (wpn.ID == wpnID)
                    {
                        add = false;
                    }
                }
                if (add)
                {
                    weaponsToAdd.Add(wpn);
                }
            }
            if (weaponsToAdd.Count == 0)
            {
                return;
            }

            int count        = WpnIDs.Length + weaponsToAdd.Count;
            int currentCount = WpnIDs.Length;
            int addCount     = weaponsToAdd.Count;


            Guid[]             wpnIDs              = new Guid[count];
            int[]              internalMagSizes    = new int[count];
            int[]              internalMagQty      = new int[count];
            int[]              reloadAmountsPerSec = new int[count];
            int[]              amountPerShot       = new int[count];
            int[]              minShotsPerfire     = new int[count];
            int[]              shotsfireThisTick   = new int[count];
            IFireWeaponInstr[] fireInstr           = new IFireWeaponInstr[count];
            double[]           launchForce         = new double[count];

            FireControlAbilityState[] fcStates = new FireControlAbilityState[count];


            if (WpnIDs.Length > 0)
            {
                Array.Copy(WpnIDs, wpnIDs, currentCount); //we can't blockcopy a non primitive.
                Array.Copy(FireControlStates, fcStates, currentCount);
                Array.Copy(FireInstructions, fireInstr, currentCount);
                Buffer.BlockCopy(InternalMagSizes, 0, internalMagSizes, 0, currentCount);
                Buffer.BlockCopy(InternalMagQty, 0, internalMagQty, 0, currentCount);
                Buffer.BlockCopy(ReloadAmountsPerSec, 0, reloadAmountsPerSec, 0, currentCount);
                Buffer.BlockCopy(AmountPerShot, 0, amountPerShot, 0, currentCount);
                Buffer.BlockCopy(MinShotsPerfire, 0, minShotsPerfire, 0, currentCount);
                Buffer.BlockCopy(ShotsFiredThisTick, 0, shotsfireThisTick, 0, currentCount);
                Buffer.BlockCopy(LaunchForces, 0, launchForce, 0, currentCount);
            }
            int offset = currentCount;

            for (int i = 0; i < addCount; i++)
            {
                GenericWeaponAtb wpnAtb = wpns[i].Design.GetAttribute <GenericWeaponAtb>();
                var wpnState            = wpns[i].GetAbilityState <WeaponState>();

                wpnIDs[i + offset]              = wpns[i].ID;
                internalMagSizes[i + offset]    = wpnAtb.InternalMagSize;
                internalMagQty[i + offset]      = wpnState.InternalMagCurAmount;
                reloadAmountsPerSec[i + offset] = wpnAtb.ReloadAmountPerSec;
                amountPerShot[i + offset]       = wpnAtb.AmountPerShot;
                minShotsPerfire[i + offset]     = wpnAtb.MinShotsPerfire;
                fcStates[i + offset]            = (FireControlAbilityState)wpnState.ParentState;
                fireInstr[i + offset]           = wpnState.FireWeaponInstructions;
                shotsfireThisTick[i]            = 0;
                if (wpns[i].Design.HasAttribute <MissileLauncherAtb>())
                {
                    launchForce[i] = wpns[i].Design.GetAttribute <MissileLauncherAtb>().LaunchForce;
                }
                else
                {
                    launchForce[i] = 1;
                }
            }

            WpnIDs              = wpnIDs;
            InternalMagSizes    = internalMagSizes;
            InternalMagQty      = internalMagQty;
            ReloadAmountsPerSec = reloadAmountsPerSec;
            AmountPerShot       = amountPerShot;
            MinShotsPerfire     = minShotsPerfire;
            FireControlStates   = fcStates;
            FireInstructions    = fireInstr;
            ShotsFiredThisTick  = shotsfireThisTick;
            LaunchForces        = launchForce;
        }