Пример #1
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);
    }