コード例 #1
0
ファイル: WeaponSetUpdate.cs プロジェクト: tecno14/OpenSAGE
 internal WeaponSetUpdate(GameObject gameObject, WeaponSetUpdateModuleData moduleData)
 {
     _gameObject = gameObject;
     _moduleData = moduleData;
 }
コード例 #2
0
        /// <summary>
        /// Converts a Generals-style WeaponSet to a C&C3-style WeaponSetUpdate.
        /// </summary>
        internal WeaponSetUpdateModuleData ToWeaponSetUpdate(AIUpdateModuleData aiUpdate)
        {
            // TODO: Need to move this up a level, to allow for multiple WeaponSets.
            var result = new WeaponSetUpdateModuleData();

            var slotsToProcess = new SortedSet <WeaponSlot>(Slots.Keys);

            var id = 1u;

            void SetWeaponSlotData(WeaponSlotHardpointData weaponSlot)
            {
                // TODO
                weaponSlot.WeaponChoiceCriteria = WeaponChoiceCriteria.PreferMostDamage;
            }

            void AddWeapon(WeaponSlotHardpointData weaponSlot, WeaponSlot slot)
            {
                if (!Slots.TryGetValue(slot, out var weaponSetSlot))
                {
                    return;
                }

                // TODO: PreferredAgainst
                // TODO: OnlyAgainst
                // TODO: AutoChooseSources

                weaponSlot.Weapons.Add(new WeaponSlotWeaponData
                {
                    Ordering = slot,
                    Template = weaponSetSlot.Weapon,
                });

                slotsToProcess.Remove(slot);
            }

            void AddWeaponSlotTurret(TurretAIUpdateModuleData turretAIData)
            {
                var weaponSlot = new WeaponSlotTurretData
                {
                    ID             = id++,
                    TurretSettings = turretAIData,
                };

                SetWeaponSlotData(weaponSlot);

                foreach (var controlledWeaponSlot in turretAIData.ControlledWeaponSlots.GetSetBits())
                {
                    AddWeapon(weaponSlot, controlledWeaponSlot);
                }

                if (weaponSlot.Weapons.Count == 0)
                {
                    return;
                }

                result.WeaponSlotTurrets.Add(weaponSlot);
            }

            if (aiUpdate?.Turret != null)
            {
                AddWeaponSlotTurret(aiUpdate.Turret);
            }

            if (aiUpdate?.AltTurret != null)
            {
                AddWeaponSlotTurret(aiUpdate.AltTurret);
            }

            // If there were any weapon slots that weren't controlled by a turret,
            // create a WeaponSlotHardpoint for them.
            if (slotsToProcess.Count > 0)
            {
                var weaponSlot = new WeaponSlotHardpointData
                {
                    ID = id++
                };

                SetWeaponSlotData(weaponSlot);

                while (slotsToProcess.Count > 0)
                {
                    var slot = slotsToProcess.Min;
                    AddWeapon(weaponSlot, slot);
                    slotsToProcess.Remove(slot);
                }

                result.WeaponSlotHardpoints.Add(weaponSlot);
            }

            return(result);
        }