/** * 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); }
/** * 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); }
/** * 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(); }