Example #1
0
 // Constructor
 public Ship(string name, Player owner)
 {
     _player     = owner;
     log         = new ShipLog(this);
     this.name   = name;
     _planet     = Terraformer.FindPlanet(EventGroup.SpaceSector);
     updateTimer = new Timer(1f, true);
 }
Example #2
0
        // Public functions
        public void OnUpdate()
        {
            // Update stats
            if (ship.status == ShipStatus.Exploring)
            {
                stamina   -= 0.1f * Time.deltaTime;
                curiosity -= 0.1f * Time.deltaTime;
            }
            else if (ship.status == ShipStatus.OnStation)
            {
                stamina   += 0.1f * Time.deltaTime;
                curiosity += 0.1f * Time.deltaTime;
            }

            // Random event
            if (Random.Percentage() <= _updateChanceCumulative || ship.log.GetMessageCount() == 0)
            {
                // Random event occured! Check if something is queued
                if (_queuedEvent != null)
                {
                    // Invoke the queued event
                    RunEvent(_queuedEvent);
                    // Clear the queued event
                    _queuedEvent = null;
                }
                // If not - select some random event
                else
                {
                    int eventGroups = EventGroup.None;
                    if (ship.status == ShipStatus.Traveling)
                    {
                        eventGroups = EventGroup.InTravel;
                    }
                    else if (ship.planet == null)
                    {
                        eventGroups = EventGroup.SpaceSector;
                    }
                    else
                    {
                        eventGroups = ship.planet.eventGroups;
                    }
                    // Invoke an event
                    RunEvent(eventGroups);
                }
                // Reset chance
                _updateChanceCumulative = updateChanceMinimal;
            }
            else
            {
                _updateChanceCumulative += updateChanceStep;
            }

            // Traveling
            if (ship.status == ShipStatus.Exploring && (stamina < 5f || curiosity < 5f))
            {
                ship.TravelTo(Terraformer.FindPlanet(EventGroup.Station));
            }
            if (ship.status == ShipStatus.OnStation && (stamina > 80f && curiosity > 90f) && storyStage > StoryStage.ShipExploration)
            {
                ship.TravelTo(Terraformer.FindPlanet(EventGroup.Planet | EventGroup.SpaceSector));
            }
        }