Exemplo n.º 1
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();
    }