Beispiel #1
0
        public void UpdateList()
        {
            weaponTypes.Clear();

            foreach(IBDWeapon weapon in vessel.FindPartModulesImplementing<IBDWeapon>())
            {
                string weaponName = weapon.GetShortName();
                bool alreadyAdded = false;
                foreach(var weap in weaponTypes)
                {
                    if(weap.GetShortName() == weaponName)
                    {
                        alreadyAdded = true;
                        break;
                    }
                }

                if(!alreadyAdded)
                {
                    weaponTypes.Add(weapon);
                }
            }

            //weaponTypes.Sort();
            weaponTypes = weaponTypes.OrderBy(w => w.GetShortName()).ToList();

            List<IBDWeapon> tempList = new List<IBDWeapon>();
            tempList.Add (null);
            tempList.AddRange(weaponTypes);

            weaponArray = tempList.ToArray();

            if(weaponIndex >= weaponArray.Length)
            {
                hasSingleFired = true;
                triggerTimer = 0;

            }

            weaponIndex = Mathf.Clamp(weaponIndex, 0, weaponArray.Length - 1);
            selectedWeapon = weaponArray[weaponIndex];
            selectedWeaponString = GetWeaponName(selectedWeapon);

            if(GetWeaponName(selectedWeapon) != GetWeaponName(weaponArray[weaponIndex])&& vessel.isActiveVessel && Time.time-startTime > 1)
            {
                hasSingleFired = true;
                if(BDArmorySettings.GAME_UI_ENABLED && vessel == FlightGlobals.ActiveVessel)
                {
                    ScreenMessages.RemoveMessage(selectionMessage);
                    selectionText = "Selected Weapon: " + GetWeaponName(weaponArray[weaponIndex]);
                    selectionMessage.message = selectionText;
                    ScreenMessages.PostScreenMessage(selectionMessage, true);
                }

            }

            ToggleTurret();
        }
Beispiel #2
0
 string GetWeaponName(IBDWeapon weapon)
 {
     if(weapon == null)
     {
         return "None";
     }
     else
     {
         return weapon.GetShortName();
     }
 }
Beispiel #3
0
        public void CycleWeapon(int index)
        {
            UpdateList();
            if(index >= weaponArray.Length)
            {
                return;
            }
            weaponIndex = index;
            selectedWeapon = weaponArray[index];
            selectedWeaponString = GetWeaponName(selectedWeapon);

            hasSingleFired = true;
            triggerTimer = 0;

            //bomb stuff
            if(selectedWeapon != null && selectedWeapon.GetWeaponClass() == WeaponClasses.Bomb)
            {
                bombPart = selectedWeapon.GetPart();
            }
            else
            {
                bombPart = null;
            }

            //gun/turret stuff
            ToggleTurret();

            if(vessel.isActiveVessel && !guardMode)
            {
                audioSource.PlayOneShot(clickSound);
            }
        }
Beispiel #4
0
        public override void OnStart(PartModule.StartState state)
        {
            UpdateMaxGuardRange();

            startTime = Time.time;

            if(HighLogic.LoadedSceneIsFlight)
            {
                part.force_activate();

                if(guardMode)
                {
                    Events["GuiToggleGuardMode"].guiName = "Guard Mode: ON";
                }
                else
                {
                    Events["GuiToggleGuardMode"].guiName = "Guard Mode: Off";
                }

                selectionMessage = new ScreenMessage("", 2, ScreenMessageStyle.LOWER_CENTER);

                UpdateList();
                if(weaponArray.Length > 0) selectedWeapon = weaponArray[weaponIndex];
                selectedWeaponString = GetWeaponName(selectedWeapon);

                cameraTransform = part.FindModelTransform("BDARPMCameraTransform");

                part.force_activate();
                rippleTimer = Time.time;
                targetListTimer = Time.time;

                Fields["guardRange"].guiActive = guardMode;
                Fields["guardAngle"].guiActive = guardMode;
                Fields["targetMissiles"].guiActive = guardMode;
                Fields["targetScanInterval"].guiActive = guardMode;

                audioSource = gameObject.AddComponent<AudioSource>();
                audioSource.minDistance = 500;
                audioSource.maxDistance = 1000;
                audioSource.dopplerLevel = 0;

                warningAudioSource = gameObject.AddComponent<AudioSource>();
                warningAudioSource.minDistance = 500;
                warningAudioSource.maxDistance = 1000;
                warningAudioSource.dopplerLevel = 0;

                targetingAudioSource = gameObject.AddComponent<AudioSource>();
                targetingAudioSource.minDistance = 100;
                targetingAudioSource.maxDistance = 1000;
                targetingAudioSource.dopplerLevel = 0;
                targetingAudioSource.loop = true;

                StartCoroutine (MissileWarningResetRoutine());

                if(vessel.isActiveVessel)
                {
                    BDArmorySettings.Instance.ActiveWeaponManager = this;
                }

                UpdateVolume();
                BDArmorySettings.OnVolumeChange += UpdateVolume;

                StartCoroutine(StartupListUpdater());
            }
        }
Beispiel #5
0
        void Update()
        {
            if(HighLogic.LoadedSceneIsFlight && FlightGlobals.ready)
            {
                if(!vessel.packed)
                {
                    if(wasGuardMode != guardMode)
                    {
                        if(!guardMode)
                        {
                            //disable turret firing and guard mode
                            foreach(var weapon in vessel.FindPartModulesImplementing<ModuleWeapon>())
                            {
                                weapon.legacyTargetVessel = null;
                                weapon.autoFire = false;
                                weapon.aiControlled = false;
                            }

                        }

                        wasGuardMode = guardMode;
                    }

                    if(weaponIndex >= weaponArray.Length)
                    {
                        hasSingleFired = true;
                        triggerTimer = 0;

                        weaponIndex = Mathf.Clamp(weaponIndex, 0, weaponArray.Length - 1);

                        if(BDArmorySettings.GAME_UI_ENABLED && vessel == FlightGlobals.ActiveVessel)
                        {
                            ScreenMessages.RemoveMessage(selectionMessage);
                            selectionText = "Selected Weapon: " + GetWeaponName(weaponArray[weaponIndex]);
                            selectionMessage.message = selectionText;
                            ScreenMessages.PostScreenMessage(selectionMessage, true);
                        }
                    }
                    if(weaponArray.Length > 0) selectedWeapon = weaponArray[weaponIndex];

                    //finding next rocket to shoot (for aimer)
                    FindNextRocket();

                    //targeting
                    if(selectedWeapon != null && (selectedWeapon.GetWeaponClass() == WeaponClasses.Missile || selectedWeapon.GetWeaponClass() == WeaponClasses.Bomb))
                    {
                        SearchForLaserPoint();
                        SearchForHeatTarget();
                        SearchForRadarSource();
                    }
                }

                UpdateTargetingAudio();
            }
        }
Beispiel #6
0
        public void CycleWeapon(bool forward)
        {
            UpdateList();
            if(forward) weaponIndex++;
            else weaponIndex--;
            weaponIndex = (int)Mathf.Repeat(weaponIndex, weaponArray.Length);

            selectedWeapon = weaponArray[weaponIndex];
            selectedWeaponString = GetWeaponName(selectedWeapon);

            hasSingleFired = true;
            triggerTimer = 0;

            if(BDArmorySettings.GAME_UI_ENABLED && vessel == FlightGlobals.ActiveVessel)
            {
                ScreenMessages.RemoveMessage(selectionMessage);
                selectionText = "Selected Weapon: " + selectedWeaponString;
                selectionMessage.message = selectionText;
                ScreenMessages.PostScreenMessage(selectionMessage, true);
            }

            //bomb stuff
            if(selectedWeapon != null && selectedWeapon.GetWeaponClass() == WeaponClasses.Bomb)
            {
                bombPart = selectedWeapon.GetPart();
            }
            else
            {
                bombPart = null;
            }

            //gun/turret stuff
            ToggleTurret();

            if(vessel.isActiveVessel && !guardMode)
            {
                audioSource.PlayOneShot(clickSound);
            }
        }
Beispiel #7
0
		public override void OnUpdate()
		{
			base.OnUpdate();

			if(!HighLogic.LoadedSceneIsFlight)
			{
				return;
			}

			if(!vessel.packed)
			{
				if(weaponIndex >= weaponArray.Length)
				{
					hasSingleFired = true;
					triggerTimer = 0;

					weaponIndex = Mathf.Clamp(weaponIndex, 0, weaponArray.Length - 1);

					DisplaySelectedWeaponMessage();
				}
				if(weaponArray.Length > 0) selectedWeapon = weaponArray[weaponIndex];

				//finding next rocket to shoot (for aimer)
				//FindNextRocket();


				//targeting
				if(weaponIndex > 0 && (selectedWeapon.GetWeaponClass() == WeaponClasses.Missile || selectedWeapon.GetWeaponClass() == WeaponClasses.Bomb))
				{
					SearchForLaserPoint();
					SearchForHeatTarget();
					SearchForRadarSource();
				}
			}

			UpdateTargetingAudio();


			if(vessel.isActiveVessel)
			{
				if(!CheckMouseIsOnGui() && isArmed && BDInputUtils.GetKey(BDInputSettingsFields.WEAP_FIRE_KEY))
				{
					triggerTimer += Time.fixedDeltaTime;	
				}
				else
				{
					triggerTimer = 0;	
					hasSingleFired = false;
				}


				//firing missiles and rockets===
				if(	!guardMode && 
					selectedWeapon != null &&
				  (selectedWeapon.GetWeaponClass() == WeaponClasses.Rocket
				  || selectedWeapon.GetWeaponClass() == WeaponClasses.Missile
				  || selectedWeapon.GetWeaponClass() == WeaponClasses.Bomb
				  ))
				{
					canRipple = true;
					if(!MapView.MapIsEnabled && triggerTimer > BDArmorySettings.TRIGGER_HOLD_TIME && !hasSingleFired)
					{
						if(rippleFire)
						{
							if(Time.time - rippleTimer > 60f / rippleRPM)
							{
								FireMissile();
								rippleTimer = Time.time;
							}
						}
						else
						{
							FireMissile();
							hasSingleFired = true;
						}
					}
				}
				else if(!guardMode && 
					selectedWeapon != null &&
					(selectedWeapon.GetWeaponClass() == WeaponClasses.Gun && currentGun.roundsPerMinute < 1500))
				{
					canRipple = true;
				}
				else
				{
					canRipple = false;
				}
			}
		}
Beispiel #8
0
		public override void OnStart (PartModule.StartState state)
		{
			UpdateMaxGuardRange();
			
			startTime = Time.time;

			UpdateTeamString();

			if(HighLogic.LoadedSceneIsFlight)
			{
				part.force_activate();

				selectionMessage = new ScreenMessage("", 2, ScreenMessageStyle.LOWER_CENTER);
				
				UpdateList();
				if(weaponArray.Length > 0) selectedWeapon = weaponArray[weaponIndex];
				//selectedWeaponString = GetWeaponName(selectedWeapon);
				
				cameraTransform = part.FindModelTransform("BDARPMCameraTransform");
				
				part.force_activate();
				rippleTimer = Time.time;
				targetListTimer = Time.time;

				wingCommander = part.FindModuleImplementing<ModuleWingCommander>();
			

				audioSource = gameObject.AddComponent<AudioSource>();
				audioSource.minDistance = 1;
				audioSource.maxDistance = 500;
				audioSource.dopplerLevel = 0;
				audioSource.spatialBlend = 1;

				warningAudioSource = gameObject.AddComponent<AudioSource>();
				warningAudioSource.minDistance = 1;
				warningAudioSource.maxDistance = 500;
				warningAudioSource.dopplerLevel = 0;
				warningAudioSource.spatialBlend = 1;

				targetingAudioSource = gameObject.AddComponent<AudioSource>();
				targetingAudioSource.minDistance = 1;
				targetingAudioSource.maxDistance = 250;
				targetingAudioSource.dopplerLevel = 0;
				targetingAudioSource.loop = true;
				targetingAudioSource.spatialBlend = 1;

				StartCoroutine (MissileWarningResetRoutine());
				
				if(vessel.isActiveVessel)
				{
					BDArmorySettings.Instance.ActiveWeaponManager = this;
				}

				UpdateVolume();
				BDArmorySettings.OnVolumeChange += UpdateVolume;
				BDArmorySettings.OnSavedSettings += ClampVisualRange;

				StartCoroutine(StartupListUpdater());

				GameEvents.onVesselCreate.Add(OnVesselCreate);
				GameEvents.onPartJointBreak.Add(OnPartJointBreak);
				GameEvents.onPartDie.Add(OnPartDie);

				foreach(var aipilot in vessel.FindPartModulesImplementing<BDModulePilotAI>())
				{
					pilotAI = aipilot;
					break;
				}
			}
		}
Beispiel #9
0
		void FindNextRocket(RocketLauncher lastFired)
		{
			if(weaponIndex > 0 && selectedWeapon.GetWeaponClass() == WeaponClasses.Rocket)
			{
				disabledRocketAimers = false;
 
				//first check sym of last fired
				if(lastFired && lastFired.part.name == selectedWeapon.GetPart().name)	
				{
					foreach(Part pSym in lastFired.part.symmetryCounterparts)
					{
						RocketLauncher rl = pSym.FindModuleImplementing<RocketLauncher>();
						bool hasRocket = false;
						foreach(PartResource r in rl.part.Resources.list)
						{
							if(r.resourceName == rl.rocketType && r.amount > 0)
							{
								hasRocket = true;
								break;
							}
						}

						if(hasRocket)
						{
							if(currentRocket) currentRocket.drawAimer = false;

							rl.drawAimer = true;
							currentRocket = rl;
							selectedWeapon = currentRocket;
							return;
						}
					}
				}

				if(!lastFired && currentRocket && currentRocket.part.name == selectedWeapon.GetPart().name)
				{
					currentRocket.drawAimer = true;
					selectedWeapon = currentRocket;
					return;
				}

				//then check for other rocket
				bool foundRocket = false;
				foreach(RocketLauncher rl in vessel.FindPartModulesImplementing<RocketLauncher>())
				{
					if(!foundRocket && rl.part.partInfo.title == selectedWeapon.GetPart().partInfo.title)
					{
						bool hasRocket = false;
						foreach(PartResource r in rl.part.Resources.list)
						{
							if(r.amount>0) hasRocket = true;
							else
							{
								rl.drawAimer = false;	
							}
						}

						if(!hasRocket) continue;

						if(currentRocket != null) currentRocket.drawAimer = false;
						rl.drawAimer = true;
						currentRocket = rl;
						selectedWeapon = currentRocket;
						//return;
						foundRocket = true;
					}
					else
					{
						rl.drawAimer = false;
					}
				}
			}
			//not using a rocket, disable reticles.
			else if(!disabledRocketAimers)
			{
				foreach(RocketLauncher rl in vessel.FindPartModulesImplementing<RocketLauncher>())
				{
					rl.drawAimer = false;
					currentRocket = null;
				}
				disabledRocketAimers = true;
			}

		}
Beispiel #10
0
		void FireCurrentMissile(bool checkClearance)
		{
			MissileLauncher ml = currentMissile;
			if(ml == null) return;

			if(checkClearance && (!CheckBombClearance(ml) || (ml.rotaryRail&&!ml.rotaryRail.readyMissile==ml)))
			{
				foreach(var otherMissile in vessel.FindPartModulesImplementing<MissileLauncher>())
				{
					if(otherMissile != ml && otherMissile.GetShortName() == ml.GetShortName() && CheckBombClearance(otherMissile))
					{
						currentMissile = otherMissile;
						selectedWeapon = otherMissile;
						FireCurrentMissile(false);
						return;
					}
				}
				currentMissile = ml;
				selectedWeapon = ml;
				return;
			}

			//Part partSym = FindSym(ml.part);
			if(ml.missileTurret)
			{
				ml.missileTurret.FireMissile(ml);
			}
			else if(ml.rotaryRail)
			{
				ml.rotaryRail.FireMissile(ml);
			}
			else
			{
				SendTargetDataToMissile(ml);
				ml.FireMissile();
			}

			if(guardMode)
			{
				if(ml.GetWeaponClass() == WeaponClasses.Bomb)
				{
					StartCoroutine(BombsAwayRoutine(ml));
				}
			}
			else
			{
				if(vesselRadarData && vesselRadarData.autoCycleLockOnFire)
				{
					vesselRadarData.CycleActiveLock();
				}
			}

			UpdateList();
		}
Beispiel #11
0
		public void UpdateList()
		{
			weaponTypes.Clear();

			foreach(IBDWeapon weapon in vessel.FindPartModulesImplementing<IBDWeapon>())
			{
				string weaponName = weapon.GetShortName();
				bool alreadyAdded = false;
				foreach(var weap in weaponTypes)
				{
					if(weap.GetShortName() == weaponName)
					{
						alreadyAdded = true;
						break;
					}
				}

				//dont add empty rocket pods
				if(weapon.GetWeaponClass() == WeaponClasses.Rocket && weapon.GetPart().FindModuleImplementing<RocketLauncher>().GetRocketResource().amount < 1)
				{
					continue;
				}

				if(!alreadyAdded)
				{
					weaponTypes.Add(weapon);
				}
			}
			
			//weaponTypes.Sort();
			weaponTypes = weaponTypes.OrderBy(w => w.GetShortName()).ToList();
			
			List<IBDWeapon> tempList = new List<IBDWeapon>();
			tempList.Add (null);
			tempList.AddRange(weaponTypes);
			
			weaponArray = tempList.ToArray();
			
			if(weaponIndex >= weaponArray.Length)
			{
				hasSingleFired = true;
				triggerTimer = 0;
				
			}

			weaponIndex = Mathf.Clamp(weaponIndex, 0, weaponArray.Length - 1);

			if(selectedWeapon == null || selectedWeapon.GetPart() == null || selectedWeapon.GetPart().vessel!=vessel || GetWeaponName(selectedWeapon) != GetWeaponName(weaponArray[weaponIndex]))
			{
				selectedWeapon = weaponArray[weaponIndex];

				if(vessel.isActiveVessel && Time.time - startTime > 1)
				{
					hasSingleFired = true;
				}

				if(vessel.isActiveVessel && weaponIndex!=0)
				{
					DisplaySelectedWeaponMessage();
				}
			}

			if(weaponIndex == 0)
			{
				selectedWeapon = null;
				hasSingleFired = true;
			}

			MissileLauncher aMl = GetAsymMissile();
			if(aMl)
			{
				//Debug.Log("setting asym missile: " + aMl.part.name);
				selectedWeapon = aMl;
				currentMissile = aMl;
			}

			MissileLauncher rMl = GetRotaryReadyMissile();
			if(rMl)
			{
				//Debug.Log("setting rotary ready missile: " + rMl.part.name);
				selectedWeapon = rMl;
				currentMissile = rMl;
			}

			if(selectedWeapon != null && (selectedWeapon.GetWeaponClass() == WeaponClasses.Bomb || selectedWeapon.GetWeaponClass() == WeaponClasses.Missile))
			{
				//Debug.Log("=====selected weapon: " + selectedWeapon.GetPart().name);
				if(!currentMissile || currentMissile.part.name != selectedWeapon.GetPart().name)
				{
					currentMissile = selectedWeapon.GetPart().FindModuleImplementing<MissileLauncher>();
				}
			}
			else
			{
				currentMissile = null;
			}

			//selectedWeapon = weaponArray[weaponIndex];

			//bomb stuff
			if(selectedWeapon != null && selectedWeapon.GetWeaponClass() == WeaponClasses.Bomb)
			{
				bombPart = selectedWeapon.GetPart();
			}
			else
			{
				bombPart = null;
			}

            //gun ripple stuff
			if(selectedWeapon != null && selectedWeapon.GetWeaponClass() == WeaponClasses.Gun && currentGun.roundsPerMinute < 1500)
            {
                float counter = 0;
                float weaponRPM = 0;
				gunRippleIndex = 0;
				rippleGunCount = 0;
                List<ModuleWeapon> tempListModuleWeapon = vessel.FindPartModulesImplementing<ModuleWeapon>();
                foreach (ModuleWeapon weapon in tempListModuleWeapon)
                {
                    if (selectedWeapon.GetShortName() == weapon.GetShortName())
                    {
						weapon.rippleIndex = Mathf.RoundToInt(counter);
                        weaponRPM = weapon.roundsPerMinute;
						++counter;
						rippleGunCount++;
                    }
                }
				gunRippleRpm = weaponRPM * counter;
                float timeDelayPerGun = 60f / (weaponRPM * counter);    //number of seconds between each gun firing; will reduce with increasing RPM or number of guns
                foreach (ModuleWeapon weapon in tempListModuleWeapon)
                {
                    if (selectedWeapon.GetShortName() == weapon.GetShortName())
                    {
                        weapon.initialFireDelay = timeDelayPerGun;        //set the time delay for moving to next index
                    }
                }

                RippleOption ro;        //ripplesetup and stuff
                if (rippleDictionary.ContainsKey(selectedWeapon.GetShortName()))
                {
                    ro = rippleDictionary[selectedWeapon.GetShortName()];
                }
                else
                {
					ro = new RippleOption(currentGun.useRippleFire, 650);       //take from gun's persistant value
                    rippleDictionary.Add(selectedWeapon.GetShortName(), ro);
                }

                foreach (ModuleWeapon w in vessel.FindPartModulesImplementing<ModuleWeapon>())
                {
                    if (w.GetShortName() == selectedWeapon.GetShortName())
                        w.useRippleFire = ro.rippleFire;
                }
            }

			//rocket
			FindNextRocket(null);
		
			ToggleTurret();
			SetMissileTurrets();
			SetRocketTurrets();
			SetRotaryRails();
		}