Ejemplo n.º 1
0
        public void SpawnEmptyContainer(string part_name)
        {
            if (vessel_spawner.LaunchInProgress)
            {
                Utils.Message("In progress...");
                return;
            }
            if (Opened)
            {
                Utils.Message("Need to close assembly space first");
                Close();
                return;
            }
            var kit_ship = new VesselKit().CreateShipConstruct(part_name, part.flagURL);

            if (kit_ship != null)
            {
                var kit_metric =
                    new Metric(kit_ship.Bounds(kit_ship.parts[0].localRoot.partTransform));
                if (!SpawnManager.MetricFits(kit_metric))
                {
                    kit_ship.Unload();
                    Utils.Message("Container is too big for this assembly space");
                    return;
                }
                PartKit.GetRequirements(kit_ship.Parts[0],
                                        out var assembly_reqs,
                                        out var construction_reqs);
                var need_ec = assembly_reqs.energy + construction_reqs.energy;
                if (!part.TryUseResource(Utils.ElectricCharge.id, need_ec))
                {
                    Utils.Message("Not enough energy to make the container");
                    kit_ship.Unload();
                    return;
                }
                if (assembly_reqs &&
                    !part.TryUseResource(assembly_reqs.resource.id,
                                         assembly_reqs.resource_amount))
                {
                    Utils.Message("Not enough {0} to make the container",
                                  assembly_reqs.resource.name);
                    kit_ship.Unload();
                    return;
                }
                if (construction_reqs &&
                    !part.TryUseResource(construction_reqs.resource.id,
                                         construction_reqs.resource_amount))
                {
                    Utils.Message("Not enough {0} to make the container",
                                  construction_reqs.resource.name);
                    kit_ship.Unload();
                    return;
                }
                GroundConstructionScenario.SaveGame(vessel.name + "-before_spawn_empty");
                StartCoroutine(spawn_kit_vessel(kit_ship));
            }
        }
Ejemplo n.º 2
0
 protected override void onLeftClick()
 {
     if (HighLogic.LoadedSceneIsEditor)
     {
         GCEditorGUI.ToggleWithButton(ALButton);
     }
     else
     {
         GroundConstructionScenario.ToggleWindow();
     }
 }
Ejemplo n.º 3
0
        private IEnumerator launch_complete_construct()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                yield break;
            }
            while (!FlightGlobals.ready)
            {
                yield return(null);
            }
            vessel_spawner.BeginLaunch();
            yield return(null);

            //save the game
            GroundConstructionScenario.SaveGame(Kit.Name + "-before_launch");
            yield return(null);

            yield return(new WaitForFixedUpdate());

            //load ship construct and launch it
            var construct = Kit.LoadConstruct();

            if (construct == null)
            {
                Utils.Log("Unable to load ShipConstruct {}. "
                          + "This usually means that some parts are missing "
                          + "or some modules failed to initialize.",
                          Kit.Name);
                Utils.Message("Something went wrong. Constructed ship cannot be launched.");
                vessel_spawner.AbortLaunch();
                yield break;
            }
            enable_damper();
            var bounds          = new Metric((IShipconstruct)construct, world_space: true).bounds;
            var spawn_transform = SpawnManager.GetSpawnTransform(bounds, out var spawn_offset);

            vessel_spawner.SpawnShipConstruct(construct,
                                              spawn_transform,
                                              spawn_offset
                                              - bounds.center
                                              + construct.Parts[0].localRoot.transform.position,
                                              Vector3.zero,
                                              null,
                                              null,
                                              null,
                                              Kit.TransferCrewToKit);
            yield return(vessel_spawner.WaitForLaunch);

            Kit = new VesselKit();
            Open();
        }
Ejemplo n.º 4
0
        IEnumerator <YieldInstruction> launch_complete_construct()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                yield break;
            }
            while (!FlightGlobals.ready)
            {
                yield return(null);
            }
            vessel_spawner.BeginLaunch();
            //hide UI
            GameEvents.onHideUI.Fire();
            yield return(null);

            //save the game
            GroundConstructionScenario.SaveGame(kit.Name + "-before_launch");
            yield return(null);

            yield return(new WaitForFixedUpdate());

            //load ship construct and launch it
            var construct = kit.LoadConstruct();

            if (construct == null)
            {
                Utils.Log("Unable to load ShipConstruct {}. "
                          + "This usually means that some parts are missing "
                          + "or some modules failed to initialize.",
                          kit.Name);
                Utils.Message("Something went wrong. Constructed ship cannot be launched.");
                GameEvents.onShowUI.Fire();
                vessel_spawner.AbortLaunch();
                yield break;
            }
            model.gameObject.SetActive(false);
            FXMonger.Explode(part, part.partTransform.position, 0);
            yield return(StartCoroutine(launch(construct)));

            GameEvents.onShowUI.Fire();
            part.Die();
        }
Ejemplo n.º 5
0
        IEnumerator <YieldInstruction> spawn_kit()
        {
            if (!Kit)
            {
                yield break;
            }
            //this.Log("Spawning kit: {}\nReqs: {}", Kit, Kit.RemainingRequirements());//debug
            if (vessel_spawner.LaunchInProgress)
            {
                Utils.Message("In progress...");
                yield break;
            }
            if (!Kit.StageComplete(DIYKit.ASSEMBLY))
            {
                Utils.Message("The kit is not yet assembled");
                yield break;
            }
            if (Kit.StageStarted(DIYKit.CONSTRUCTION))
            {
                Utils.Message("Kit construction is already started");
                yield break;
            }
            if (HasAnimator && Opened)
            {
                Utils.Message("Need to close assembly space first");
                Close();
                yield break;
            }
            yield return(new WaitForEndOfFrame());

            yield return(new WaitForFixedUpdate());

            var kit_ship = Kit.CreateShipConstruct(KitPart, part.flagURL);

            if (kit_ship == null)
            {
                yield break;
            }
            GroundConstructionScenario.SaveGame(Kit.Name + "-before_spawn");
            yield return(StartCoroutine(spawn_kit_vessel(kit_ship)));
        }
Ejemplo n.º 6
0
        private void update_and_checkin(Vessel vsl)
        {
            if (vsl == vessel && vessel != null)
            {
                if (vessel.loaded)
                {
                    Workshops.Clear();
                    ProtoWorkshops.Clear();
                    foreach (var p in vessel.Parts)
                    {
                        var ws = p.Modules.GetModule <WorkshopBase>();
                        if (ws != null && ws.isEnabled)
                        {
                            add_workshop(ws);
                        }
                    }
                }
                else
                {
                    foreach (var pp in vessel.protoVessel.protoPartSnapshots)
                    {
                        var pm = pp.FindModule(nameof(WorkshopBase));
                        if (pm == null)
                        {
                            continue;
                        }
                        add_protoworkshop(new ProtoWorkshop(vessel.id,
                                                            vessel.vesselName,
                                                            pp.flightID,
                                                            pp.partInfo.title,
                                                            pm.moduleValues));
                    }
                }
                if (!Empty)
                {
                    GroundConstructionScenario.CheckinVessel(this);
                }
//                this.Log("update_and_checkin.ProtoWorkshops: {}", ProtoWorkshops);//debug
            }
        }
Ejemplo n.º 7
0
        public void SpawnKit()
        {
            if (!Kit)
            {
                return;
            }
            //this.Log("Spawning kit: {}\nReqs: {}", Kit, Kit.RemainingRequirements());//debug
            if (vessel_spawner.LaunchInProgress)
            {
                Utils.Message("In progress...");
                return;
            }
            if (!Kit.StageComplete(DIYKit.ASSEMBLY))
            {
                Utils.Message("The kit is not yet assembled");
                return;
            }
            if (Kit.StageStarted(DIYKit.CONSTRUCTION))
            {
                Utils.Message("Kit construction is already started");
                return;
            }
            if (Opened)
            {
                Utils.Message("Need to close assembly space first");
                Close();
                return;
            }
            var kit_ship = Kit.CreateShipConstruct(KitPart, part.flagURL);

            if (kit_ship != null)
            {
                GroundConstructionScenario.SaveGame(Kit.Name + "-before_spawn");
                StartCoroutine(spawn_kit_vessel(kit_ship));
            }
        }
Ejemplo n.º 8
0
 protected void start_deployment()
 {
     GroundConstructionScenario.SaveGame(Name + "-before_deployment");
     state = DeploymentState.DEPLOYING;
     StartCoroutine(deploy());
 }