예제 #1
0
        public void partDieEvent(Part part)
        {
            BeanCounter.LogFormatted_DebugOnly("---------- partDieEvent ------------");

            // Get the launch that this part was from
            BCLaunchData launch =
                (from launchq in OATBeanCounterData.data.launches
                 where launchq.missionID == part.missionID
                 select launchq).SingleOrDefault();

            if (launch == null)
            {
                BeanCounter.LogFormatted_DebugOnly("Could not find launch for missionID {0}", part.missionID);
                return;
            }

            // Get the VesselPartData for the part that died
            BCVesselPartData partdata =
                (from partq in launch.parts
                 where partq.uid == part.flightID
                 select partq).SingleOrDefault();

            if (partdata == null)
            {
                BeanCounter.LogFormatted_DebugOnly("Could not find part for flightID {0}", part.flightID);
                return;
            }

            BCPartDestructionData destruction = new BCPartDestructionData();

            destruction.time = HighLogic.CurrentGame.UniversalTime;

            partdata.status      = BCVesselPartStatus.Destroyed;
            partdata.destruction = destruction;

            BeanCounter.LogFormatted_DebugOnly("--------- /partDieEvent ------------");
        }
예제 #2
0
		/// <summary>
		/// Fires when a new vessel is created at the launch pad.
		/// </summary>
		/// <param name="ship">The ship being rolled out.</param>
		public void vesselRolloutEvent(ShipConstruct ship)
		{
			BeanCounter.LogFormatted_DebugOnly("------------- vesselRolloutEvent -------------");

			float dryCost, fuelCost, totalCost;
			totalCost = ship.GetShipCosts (out dryCost, out fuelCost);

			BeanCounter.LogFormatted_DebugOnly("Rollout: {0}", ship.shipName);
			BeanCounter.LogFormatted_DebugOnly("launchID: {0}", HighLogic.fetch.currentGame.launchID);

			Vessel vessel = FlightGlobals.ActiveVessel;
			BeanCounter.LogFormatted_DebugOnly("NEW VESSEL LAUNCH DETECTED: {0}", vessel.vesselName);
			
			BCLaunchData launch = new BCLaunchData(true);
			launch.vesselName = vessel.vesselName;
			launch.missionID = BCUtils.GetVesselMissionID(vessel);
			launch.dryCost = dryCost;
			launch.totalCost = totalCost;
			launch.launchTime = vessel.launchTime;

			// TODO move this to utils?
			List<BCVesselResourceData> resources = new List<BCVesselResourceData>();
			List<BCVesselPartData> parts = new List<BCVesselPartData>();
			float total_resource_cost = 0;
			
            // Iterate over each part so we can log the parts, calculate the vessel resources, and
            // calculate the actual cost of everything
			foreach (Part part in vessel.parts)
			{
				BCVesselPartData part_data = new BCVesselPartData();
				part_data.partName = part.partInfo.name;
				
				float part_full_cost = part.partInfo.cost;
				float part_resource_cost_full = 0;
				float part_resource_cost_actual = 0;
				
				foreach (PartResource res in part.Resources)
				{
					if (res.info.unitCost == 0 || res.amount == 0)
					{
						// Don't need to keep track of free resources
						// Or maybe we should, in case the cost changes due to a mod/game update?
						continue;
					}
					
					part_resource_cost_full += (float)(res.info.unitCost * res.maxAmount);
					part_resource_cost_actual += (float)(res.info.unitCost * res.amount);
					
                    // Either create a new VesselResourceData, or add to the one we already have
                    // TODO perhaps this should be conbined in to a single static method on BCVesselResourceData?
					BCVesselResourceData vr = resources.Find(r => r.resourceName == res.resourceName);
					if (vr == null)
					{
						resources.Add(new BCVesselResourceData(res.info, res.resourceName, res.amount, res.maxAmount));
					}
					else
					{
						vr.Add(res);
					}
				}
				
				float part_dry_cost = part_full_cost - part_resource_cost_full;
				part_data.baseCost = part_dry_cost;
				part_data.moduleCosts = part.GetModuleCosts();
				part_data.status = BCVesselPartStatus.Active;
				part_data.uid = part.flightID;
				parts.Add(part_data);

				total_resource_cost += part_resource_cost_actual;
			}
			
			launch.resources = resources;
			launch.parts = parts;
			launch.resourceCost = total_resource_cost;
			OATBeanCounterData.data.launches.Add(launch);

            // Try to match this to the transaction
            BCTransactionData transaction =
                (from trans in OATBeanCounterData.data.transactions
                 where trans.time == HighLogic.CurrentGame.UniversalTime
                 && trans.reason == TransactionReasons.VesselRollout
                 select trans).SingleOrDefault();
            if (transaction != null)
            {
                BeanCounter.LogFormatted_DebugOnly("Found matching transaction for this rollout: {0}", transaction.id);
                launch.transactionID = transaction.id;
                transaction.dataID = launch.id;
            }

			BeanCounter.LogFormatted_DebugOnly("------------ /vesselRolloutEvent -------------");
		}
예제 #3
0
        /// <summary>
        /// Fires when a new vessel is created at the launch pad.
        /// </summary>
        /// <param name="ship">The ship being rolled out.</param>
        public void vesselRolloutEvent(ShipConstruct ship)
        {
            BeanCounter.LogFormatted_DebugOnly("------------- vesselRolloutEvent -------------");

            float dryCost, fuelCost, totalCost;

            totalCost = ship.GetShipCosts(out dryCost, out fuelCost);

            BeanCounter.LogFormatted_DebugOnly("Rollout: {0}", ship.shipName);
            BeanCounter.LogFormatted_DebugOnly("launchID: {0}", HighLogic.fetch.currentGame.launchID);

            Vessel vessel = FlightGlobals.ActiveVessel;

            BeanCounter.LogFormatted_DebugOnly("NEW VESSEL LAUNCH DETECTED: {0}", vessel.vesselName);

            BCLaunchData launch = new BCLaunchData(true);

            launch.vesselName = vessel.vesselName;
            launch.missionID  = BCUtils.GetVesselMissionID(vessel);
            launch.dryCost    = dryCost;
            launch.totalCost  = totalCost;
            launch.launchTime = vessel.launchTime;

            // TODO move this to utils?
            List <BCVesselResourceData> resources = new List <BCVesselResourceData>();
            List <BCVesselPartData>     parts     = new List <BCVesselPartData>();
            float total_resource_cost             = 0;

            // Iterate over each part so we can log the parts, calculate the vessel resources, and
            // calculate the actual cost of everything
            foreach (Part part in vessel.parts)
            {
                BCVesselPartData part_data = new BCVesselPartData();
                part_data.partName = part.partInfo.name;

                float part_full_cost            = part.partInfo.cost;
                float part_resource_cost_full   = 0;
                float part_resource_cost_actual = 0;

                foreach (PartResource res in part.Resources)
                {
                    if (res.info.unitCost == 0 || res.amount == 0)
                    {
                        // Don't need to keep track of free resources
                        // Or maybe we should, in case the cost changes due to a mod/game update?
                        continue;
                    }

                    part_resource_cost_full   += (float)(res.info.unitCost * res.maxAmount);
                    part_resource_cost_actual += (float)(res.info.unitCost * res.amount);

                    // Either create a new VesselResourceData, or add to the one we already have
                    // TODO perhaps this should be conbined in to a single static method on BCVesselResourceData?
                    BCVesselResourceData vr = resources.Find(r => r.resourceName == res.resourceName);
                    if (vr == null)
                    {
                        resources.Add(new BCVesselResourceData(res.info, res.resourceName, res.amount, res.maxAmount));
                    }
                    else
                    {
                        vr.Add(res);
                    }
                }

                float part_dry_cost = part_full_cost - part_resource_cost_full;
                part_data.baseCost    = part_dry_cost;
                part_data.moduleCosts = part.GetModuleCosts();
                part_data.status      = BCVesselPartStatus.Active;
                part_data.uid         = part.flightID;
                parts.Add(part_data);

                total_resource_cost += part_resource_cost_actual;
            }

            launch.resources    = resources;
            launch.parts        = parts;
            launch.resourceCost = total_resource_cost;
            OATBeanCounterData.data.launches.Add(launch);

            // Try to match this to the transaction
            BCTransactionData transaction =
                (from trans in OATBeanCounterData.data.transactions
                 where trans.time == HighLogic.CurrentGame.UniversalTime &&
                 trans.reason == TransactionReasons.VesselRollout
                 select trans).SingleOrDefault();

            if (transaction != null)
            {
                BeanCounter.LogFormatted_DebugOnly("Found matching transaction for this rollout: {0}", transaction.id);
                launch.transactionID = transaction.id;
                transaction.dataID   = launch.id;
            }

            BeanCounter.LogFormatted_DebugOnly("------------ /vesselRolloutEvent -------------");
        }