Ejemplo n.º 1
0
        /// <summary>Creates a new, AI controlled ship.</summary>
        /// <param name="manager">The manager.</param>
        /// <param name="blueprint">The blueprint.</param>
        /// <param name="faction">The faction the ship will belong to.</param>
        /// <param name="position">The position.</param>
        /// <param name="random">The random.</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>The new ship.</returns>
        public static int CreateAIShip(
            IManager manager,
            string blueprint,
            Factions faction,
            FarPosition position,
            IUniformRandom random,
            ArtificialIntelligence.AIConfiguration configuration = null)
        {
            var entity = FactoryLibrary.SampleShip(manager, blueprint, faction, position, random);

            var input = (ShipControl)manager.GetComponent(entity, ShipControl.TypeId);

            input.Stabilizing = true;
            manager.AddComponent <ArtificialIntelligence>(entity).
            Initialize(random != null ? random.NextUInt32() : 0, configuration).Enabled = false;

            // Add to the index from which entities will automatically removed
            // on cell death and mark it (for translation checks into empty space).
            manager.AddComponent <Indexable>(entity).Initialize(CellSystem.CellDeathAutoRemoveIndexId);
            manager.AddComponent <CellDeath>(entity).Initialize(true);

            // Add to AI index, to allow putting the AI to sleep.
            manager.AddComponent <Indexable>(entity).Initialize(SleepSystem.IndexId);

            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>Creates a new, player controlled ship.</summary>
        /// <param name="manager">The manager.</param>
        /// <param name="playerClass">The player's class, which determines the blueprint.</param>
        /// <param name="playerNumber">The player for whom to create the ship.</param>
        /// <param name="position">The position at which to spawn and respawn the ship.</param>
        /// <returns>The new ship.</returns>
        public static int CreatePlayerShip(
            IManager manager, PlayerClassType playerClass, int playerNumber, FarPosition position)
        {
            // Player ships must be 'static', i.e. not have random attributes, so we don't need a randomizer.
            var entity = FactoryLibrary.SampleShip(
                manager, playerClass.GetShipFactoryName(), playerNumber.ToFaction(), position, null);

            // Remember the class.
            manager.AddComponent <PlayerClass>(entity).Initialize(playerClass);

            // Mark it as the player's avatar.
            manager.AddComponent <Avatar>(entity).Initialize(playerNumber);

            // Make it respawn (after 5 seconds).
            manager.AddComponent <Respawn>(entity).Initialize(
                (int)(5 * Settings.TicksPerSecond),
                new HashSet <Type>
            {
                // Make ship uncontrollable.
                typeof(ShipControl),
                typeof(WeaponControl),
                // Disable collisions.
                typeof(Body),
                // And movement.
                typeof(Gravitation),
                // Hide it.
                typeof(ShipDrawable),
                typeof(ParticleEffects),
                // And don't regenerate.
                typeof(Health),
                typeof(Energy)
            },
                position);

            // Allow leveling up.
            manager.AddComponent <Experience>(entity).Initialize(100, 100f, 2.15f);

            // Make player ships collide more precisely. We don't much care for NPC ships tunneling
            // through stuff (unlikely as that may be anyways), but we really don't want it to happen
            // for a player ship.
            var body = (Body)manager.GetComponent(entity, Body.TypeId);

            body.IsBullet = true;

            return(entity);
        }