Example #1
0
		void ParseRippleOptions()
		{
			rippleDictionary = new Dictionary<string, RippleOption>();
			Debug.Log("Parsing ripple options");
			if(!string.IsNullOrEmpty(rippleData))
			{
				Debug.Log("Ripple data: " + rippleData);
				try
				{
					foreach(string weapon in rippleData.Split(new char[]{';'}))
					{
						if(weapon == string.Empty) continue;

						string[] options = weapon.Split(new char[]{ ',' });
						string wpnName = options[0];
						bool rf = bool.Parse(options[1]);
						float _rpm = float.Parse(options[2]);
						RippleOption ro = new RippleOption(rf, _rpm);
						rippleDictionary.Add(wpnName, ro);
					}
				}
				catch(IndexOutOfRangeException)
				{
					Debug.Log("Ripple data was invalid.");
					rippleData = string.Empty;
				}
			}
			else
			{
				Debug.Log("Ripple data is empty.");
			}

			if(vessel)
			{
				foreach(var rl in vessel.FindPartModulesImplementing<RocketLauncher>())
				{
					if(!rl) continue;

					if(!rippleDictionary.ContainsKey(rl.GetShortName()))
					{
						rippleDictionary.Add(rl.GetShortName(), new RippleOption(false, 650f));
					}
				}
			}

			hasLoadedRippleData = true;
		}
Example #2
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();
		}
Example #3
0
		public void ToggleRippleFire()
		{
			if(selectedWeapon != null)
			{
				RippleOption ro;
				if(rippleDictionary.ContainsKey(selectedWeapon.GetShortName()))
				{
					ro = rippleDictionary[selectedWeapon.GetShortName()];
				}
				else
				{
					ro = new RippleOption(false, 650);       //default to true ripple fire for guns, otherwise, false
					if(selectedWeapon.GetWeaponClass() == WeaponClasses.Gun)
					{
						ro.rippleFire = currentGun.useRippleFire;
					}
					rippleDictionary.Add(selectedWeapon.GetShortName(), ro);
				}

				ro.rippleFire = !ro.rippleFire;

                if(selectedWeapon.GetWeaponClass() == WeaponClasses.Gun)
                {
                    foreach(ModuleWeapon w in vessel.FindPartModulesImplementing<ModuleWeapon>())
                    {
                        if (w.GetShortName() == selectedWeapon.GetShortName())
                            w.useRippleFire = ro.rippleFire;
                    }
                }
			}
		}
Example #4
0
        public void ToggleRippleFire()
        {
            if(selectedWeapon != null)
            {
                RippleOption ro;
                if(rippleDictionary.ContainsKey(selectedWeapon.GetShortName()))
                {
                    ro = rippleDictionary[selectedWeapon.GetShortName()];
                }
                else
                {
                    ro = new RippleOption(false, 650);
                    rippleDictionary.Add(selectedWeapon.GetShortName(), ro);
                }

                ro.rippleFire = !ro.rippleFire;
            }
        }