Пример #1
0
 /**
  * construct hull based on manifest
  */
 void Construct(HullManifest manifest)
 {
     this.manifest = manifest;
     foreach (ExternalModuleManifest extModManifest in manifest.modules)
     {
         HullSlot slot;
         if (!slots.TryGetValue(extModManifest.position, out slot))
         {
             slot = Instantiate(slotPrefab) as HullSlot;
             slot.transform.parent        = transform;
             slot.transform.localPosition = extModManifest.position;
             slots.Add(extModManifest.position, slot);
         }
         ExternalConstructionModule extMod = Instantiate(game.GetConstructionModulePrefab(extModManifest.type)) as ExternalConstructionModule;
         extMod.transform.localRotation = extModManifest.rotation;
         extMod.stats         = extModManifest.stats;
         extMod.hitPointsLeft = extModManifest.hitPointsLeft;
         extMod.manifest      = extModManifest;
         Equip(extMod, slot);
         if (extMod is HullConstructionModule)
         {
             if (extModManifest.internalModule != null)
             {
                 InternalConstructionModule intMod = Instantiate(game.GetConstructionModulePrefab(extModManifest.internalModule.type)) as InternalConstructionModule;
                 intMod.stats         = extModManifest.internalModule.stats;
                 intMod.hitPointsLeft = extModManifest.internalModule.hitPointsLeft;
                 intMod.SetContents(extModManifest.internalModule.contents);
                 intMod.manifest = extModManifest.internalModule;
                 Equip(intMod, (HullConstructionModule)extMod);
             }
         }
     }
 }
Пример #2
0
    void OnGUI()
    {
        GUI.BeginGroup(new Rect(10, 10, Screen.width - 20, 40));
        if (GUI.Button(new Rect(0, 0, 180, 40), "Combat")) {
            game.ChangeScene("Combat");
        }
        if (GUI.Button(new Rect(190, 0, 180, 40), "Navigate")) {
            game.Navigate();
        }
        GUI.EndGroup();

        GUILayout.BeginArea(new Rect(10, 10, 250, Screen.height - 20));
        GUILayout.BeginVertical();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Clear")) {
            hullManifest = null;
            inventoryManifest = null;
            hull.Reset();
            inventory.Reset();
        }
        if (GUILayout.Button("Reset")) {
            hull.Reset();
            inventory.Reset();
        }
        if (GUILayout.Button("Save")) {
            // Save the game with a prefix of Game
            var t = DateTime.Now;
            hull.Save();
            inventory.Save();
            LevelSerializer.SaveGame("Game");
            Radical.CommitLog();
            Debug.Log(string.Format("{0:0.000}", (DateTime.Now - t).TotalSeconds));
        }

        // Check to see if there is resume info
        if (LevelSerializer.CanResume) {
            if (GUILayout.Button("Resume")) {
                LevelSerializer.Resume();
            }
        }

        if (LevelSerializer.SavedGames.Count > 0) {
            GUILayout.Label("Available saved games");
            // Look for saved games under the given player name
            foreach (var g in LevelSerializer.SavedGames[LevelSerializer.PlayerName]) {
                if (GUILayout.Button(g.Caption)) {
                    g.Load();
                }

            }
        }

        if (GUILayout.Button("Delete All")) {
            PlayerPrefs.DeleteAll();
        }
        GUILayout.EndVertical();
        GUILayout.EndArea();
    }
Пример #3
0
    /**
     * Save state to manifest
     */
    public HullManifest CreateManifest()
    {
        HullManifest manifest = new HullManifest(this);

        manifest.velocity        = rigidbody.velocity;
        manifest.angularVelocity = rigidbody.angularVelocity;

        // location
        if (constellation != null)
        {
            manifest.constellation = constellation.Manifest.position;
            if (star != null)
            {
                manifest.star = star.manifest.index;
                if (planet != null)
                {
                    manifest.planet = planet.index;
                }
            }
        }

        // ship modules
        foreach (var extMod in modules)
        {
            if (extMod is InternalCombatModule || extMod.hitPointsLeft == 0)
            {
                continue;
            }
            ExternalModuleManifest extModManifest = new ExternalModuleManifest(
                extMod.transform.localPosition,
                extMod.transform.localRotation
                );
            extModManifest.type          = (ModuleType)extMod.GetType().GetField("type").GetRawConstantValue();
            extModManifest.stats         = extMod.stats;
            extModManifest.hitPointsLeft = extMod.hitPointsLeft;

            // internal module
            manifest.modules.Add(extModManifest);
            if (extMod is HullCombatModule)
            {
                InternalCombatModule intMod = ((HullCombatModule)extMod).internalModule;
                if (intMod != null && intMod.hitPointsLeft > 0)
                {
                    InternalModuleManifest intModManifest = new InternalModuleManifest(extMod);
                    intModManifest.type           = (ModuleType)intMod.GetType().GetField("type").GetRawConstantValue();
                    intModManifest.stats          = intMod.stats;
                    intModManifest.hitPointsLeft  = intMod.hitPointsLeft;
                    intModManifest.contents       = intMod.GetContents();
                    extModManifest.internalModule = intModManifest;
                }
            }
        }
        this.manifest = manifest;
        return(manifest);
    }
Пример #4
0
    /**
     * Save state to manifest
     */
    public HullManifest CreateManifest()
    {
        HullManifest manifest = new HullManifest();

        manifest.position        = this.manifest.position;
        manifest.rotation        = this.manifest.rotation;
        manifest.velocity        = this.manifest.velocity;
        manifest.angularVelocity = this.manifest.angularVelocity;
        manifest.constellation   = this.manifest.constellation;
        manifest.star            = this.manifest.star;
        manifest.planet          = this.manifest.planet;
        foreach (KeyValuePair <Vector3, HullSlot> pair in slots)
        {
            // external module
            ExternalConstructionModule extMod = pair.Value.module;
            if (extMod == null)
            {
                continue;
            }
            ExternalModuleManifest extModManifest = new ExternalModuleManifest(
                extMod.hullSlot.transform.localPosition,
                extMod.transform.localRotation
                );
            extModManifest.name          = extMod.manifest.name;
            extModManifest.type          = (ModuleType)extMod.GetType().GetField("type").GetRawConstantValue();
            extModManifest.stats         = extMod.stats;
            extModManifest.hitPointsLeft = extMod.hitPointsLeft;

            // internal module
            manifest.modules.Add(extModManifest);
            if (extMod is HullConstructionModule)
            {
                InternalConstructionModule intMod = ((HullConstructionModule)extMod).internalModule;
                if (intMod != null)
                {
                    InternalModuleManifest intModManifest = new InternalModuleManifest(extMod.hullSlot);
                    intModManifest.name           = intMod.manifest.name;
                    intModManifest.type           = (ModuleType)intMod.GetType().GetField("type").GetRawConstantValue();
                    intModManifest.stats          = intMod.stats;
                    intModManifest.hitPointsLeft  = intMod.hitPointsLeft;
                    intModManifest.contents       = intMod.GetContents();
                    extModManifest.internalModule = intModManifest;
                }
            }
        }
        this.manifest = manifest;
        return(manifest);
    }
Пример #5
0
    /**
     * Reset to last loaded state
     */
    public void Reset()
    {
        Clear();

        // no manifest, use scene
        if (scene.hullManifest == null)
        {
            HullSlot slot = Instantiate(slotPrefab) as HullSlot;
            slot.transform.parent        = transform;
            slot.transform.localPosition = Vector3.zero;
            slots.Add(Vector3.zero, slot);
            manifest                 = new HullManifest();
            manifest.position        = Vector3.zero;
            manifest.rotation        = Quaternion.identity;
            manifest.velocity        = Vector3.zero;
            manifest.angularVelocity = Vector3.zero;
        }

        // manifest exists, construct hull based on manifest
        else
        {
            Construct(scene.hullManifest);
        }
    }
Пример #6
0
 protected override void Awake()
 {
     base.Awake();
     hullManifest = game.hullManifest;
     inventoryManifest = game.inventoryManifest;
 }
Пример #7
0
    /**
     * construct ship based on manifest
     */
    virtual protected void Construct(HullManifest manifest)
    {
        this.manifest             = manifest;
        rigidbody.velocity        = manifest.velocity;
        rigidbody.angularVelocity = manifest.angularVelocity;
        transform.position        = manifest.position;
        transform.localRotation   = manifest.rotation;

        // location
        if (manifest.constellation != null)
        {
            constellation = scene.GetConstellation((Vector3)manifest.constellation);
            if (manifest.star != null && constellation.Stars.Count > 0)
            {
                star = constellation.Stars[(int)manifest.star];
                if (manifest.planet != null && star.planets.Count > 0)
                {
                    planet = star.planets[(int)manifest.planet];
                }
            }
        }

        // parts
        foreach (ExternalModuleManifest extModManifest in manifest.modules)
        {
            ExternalCombatModule extMod = Instantiate(game.GetCombatModulePrefab(extModManifest.type)) as ExternalCombatModule;
            extMod.transform.parent        = transform;
            extMod.transform.localPosition = extModManifest.position;
            extMod.transform.localRotation = extModManifest.rotation;
            extMod.stats         = extModManifest.stats;
            extMod.hitPointsLeft = extModManifest.hitPointsLeft;
            extMod.ship          = this;
            if (extMod is FuelCombatModule)
            {
                ((FuelModuleStats)extMod.stats).capacity = 10;
            }
            if (extMod is ThrusterCombatModule)
            {
                propulsionSystem.AddThruster((ThrusterCombatModule)extMod);
                ((ThrusterModuleStats)extMod.stats).thrust = 10;
            }
            else if (extMod is ManeuveringCombatModule)
            {
                propulsionSystem.AddManeuverer((ManeuveringCombatModule)extMod);
                ((ManeuveringModuleStats)extMod.stats).thrust = 10;
            }
            else if (extMod is WeaponCombatModule)
            {
                weaponSystem.AddWeapon((WeaponCombatModule)extMod);
            }
            else if (extMod is HullCombatModule)
            {
                modules.Add(extMod);

                // internal module mounted on top of hull module
                InternalModuleManifest intModManifest = extModManifest.internalModule;
                if (intModManifest != null)
                {
                    InternalCombatModule intMod = Instantiate(game.GetCombatModulePrefab(intModManifest.type)) as InternalCombatModule;
                    intMod.transform.parent        = transform;
                    intMod.transform.localPosition = intModManifest.position;
                    intMod.transform.localRotation = intModManifest.rotation;
                    intMod.stats         = intModManifest.stats;
                    intMod.hitPointsLeft = intModManifest.hitPointsLeft;
                    intMod.SetContents(intModManifest.contents);
                    intMod.ship = this;
                    ((HullCombatModule)extMod).internalModule = intMod;
                    if (intMod is CrewCombatModule)
                    {
                        crewSystem.AddCrewPod((CrewCombatModule)intMod);
                    }
                    else if (intMod is BatteryCombatModule)
                    {
                        energySystem.AddBattery((BatteryCombatModule)intMod);
                    }
                    else if (intMod is PowerCombatModule)
                    {
                        energySystem.AddPowerPlant((PowerCombatModule)intMod);
                    }
                    else if (intMod is FuelCombatModule)
                    {
                        propulsionSystem.AddFuelTank((FuelCombatModule)intMod);
                    }
                }
            }
        }
        CalcBounds();
    }
Пример #8
0
    void OnGUI()
    {
        GUI.BeginGroup(new Rect(10, 10, Screen.width - 20, 40));
        if (GUI.Button(new Rect(0, 0, 180, 40), "Combat"))
        {
            game.ChangeScene("Combat");
        }
        if (GUI.Button(new Rect(190, 0, 180, 40), "Navigate"))
        {
            game.Navigate();
        }
        GUI.EndGroup();

        GUILayout.BeginArea(new Rect(10, 10, 250, Screen.height - 20));
        GUILayout.BeginVertical();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Clear"))
        {
            hullManifest      = null;
            inventoryManifest = null;
            hull.Reset();
            inventory.Reset();
        }
        if (GUILayout.Button("Reset"))
        {
            hull.Reset();
            inventory.Reset();
        }
        if (GUILayout.Button("Save"))
        {
            // Save the game with a prefix of Game
            var t = DateTime.Now;
            hull.Save();
            inventory.Save();
            LevelSerializer.SaveGame("Game");
            Radical.CommitLog();
            Debug.Log(string.Format("{0:0.000}", (DateTime.Now - t).TotalSeconds));
        }

        // Check to see if there is resume info
        if (LevelSerializer.CanResume)
        {
            if (GUILayout.Button("Resume"))
            {
                LevelSerializer.Resume();
            }
        }

        if (LevelSerializer.SavedGames.Count > 0)
        {
            GUILayout.Label("Available saved games");
            // Look for saved games under the given player name
            foreach (var g in LevelSerializer.SavedGames[LevelSerializer.PlayerName])
            {
                if (GUILayout.Button(g.Caption))
                {
                    g.Load();
                }
            }
        }

        if (GUILayout.Button("Delete All"))
        {
            PlayerPrefs.DeleteAll();
        }
        GUILayout.EndVertical();
        GUILayout.EndArea();
    }
Пример #9
0
 override protected void Awake()
 {
     base.Awake();
     hullManifest      = game.hullManifest;
     inventoryManifest = game.inventoryManifest;
 }