Exemplo n.º 1
0
        private void updateRecord(IEtsInterface p)
        {
            //record.controlButton |= p.WasControlButtonPressed();
            //for (int i = 0; i < record.lights.Length; i++)
            //record.lights[i] |= p.GetLightState(i);

            bool anyActionRegistered = false;

            p.ForcePipesUpdate();
            int psi = 0;

            foreach (PipeSystem ps in pipes.PipeSystems())
            {
                int vi = 0;
                foreach (Valve v in ps.Valves())
                {
                    record.valvesPerPipeSystem_Rotating[psi][vi] |= p.IsValveRotating(v.Row, v.PositionInRow);
                    anyActionRegistered |= record.valvesPerPipeSystem_Rotating[psi][vi];
                    record.valvesPerPipeSystem_StateChanges[psi][vi] |= (p.GetValveState(v.Row, v.PositionInRow) != initialValveStates[psi][vi]);
                    anyActionRegistered |= record.valvesPerPipeSystem_StateChanges[psi][vi];
                    vi++;
                }
                int fi = 0;
                foreach (Fan f in ps.Fans())
                {
                    record.fansPerPipeSystem[psi][fi] |= p.GetFanState(f.Row, f.PositionInRow);
                    anyActionRegistered |= record.fansPerPipeSystem[psi][fi];
                    fi++;
                }
                psi++;
            }

            p.ForceCraneUpdate();
            for (int i = 0; i < CratesGame.ButtonCount; i++)
            {
                record.craneButtons[i] |= p.WasCraneButtonPressed(i);
                anyActionRegistered    |= record.craneButtons[i];
            }

            p.ForceDynamiteUpdate();
            for (int i = 0; i < DynamiteGame.HoleCount; i++)
            {
                record.holes[i]     |= (p.GetHoleState(i) != initialHoleStates[i]);
                anyActionRegistered |= record.holes[i];
            }

            p.ForceTriggerUpdate();
            for (int i = 0; i < TriggersGame.ButtonCount; i++)
            {
                record.triggerButtons[i] |= p.WasSequenceButtonPressed(i);
                anyActionRegistered      |= record.triggerButtons[i];
            }

            if (anyActionRegistered)
            {
                audio.PlaySound(actionRegisteredSound);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This resets the valves to be open or closed according to the predefined initial configuration, or a random
        /// state with no running fans if no preset was specified.
        /// To determine the logical closed state of a valve, its current physical state is read for reference. The
        /// logical closed state is then adjusted to match or deviate from the current physical states.
        /// See <see cref="Valve.IsOpen"/>.
        /// </summary>
        /// <param name="physical">the physical interface to get the physical valve states from</param>
        public void Initialize(IEtsInterface physical)
        {
            Log.Verbose("Initializing pipe system " + Index);

            // store the current physical states of each valve for reference
            foreach (Valve v in valves)
            {
                v.currentPhysicalState = physical.GetValveState(v.Row, v.PositionInRow);
                //Log.Debug("Initialized valve with physical state " + v.currentPhysicalState);
            }

            // if the set of open valves is predefined: apply the preset
            if (openValvesAtStart != null)
            {
                foreach (Valve v in valves)
                {
                    // if the valve is not reported as broken by the physical interface, set the logical closed state as intended
                    if (!physical.IsValveBroken(v.Row, v.PositionInRow))
                    {
                        v.logicalClosedState = openValvesAtStart.Contains(v) ? !v.currentPhysicalState : v.currentPhysicalState;
                    }

                    // otherwise, override it such that the system can be solved without turning this valve (i.e. closed iff the valve is connected to an outlet)
                    else
                    {
                        bool connectedToOutlet = false;
                        foreach (Edge e in graph.AdjacentEdges(v))
                        {
                            if (e.GetOtherVertex((Vertex)v) is Outlet)
                            {
                                connectedToOutlet = true;
                            }
                        }
                        v.logicalClosedState = connectedToOutlet ? v.currentPhysicalState : !v.currentPhysicalState;
                    }
                }
                RunningFansCount = findCorrectlyConnectedFans().Count;
            }
            // otherwise: set up a random configuration with no running fans
            else
            {
                int runningFans = 1;
                while (runningFans > 0)
                {
                    foreach (Valve v in valves)
                    {
                        v.currentPhysicalState = r.Next(0, 1) == 1;
                    }
                    RunningFansCount = findCorrectlyConnectedFans().Count;
                    if (RunningFansCount > 0)
                    {
                        Log.Debug("Discarding initial valves configuration with {0} running fans.", runningFans);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public HashSet <Vertex> Update(IEtsInterface physical)
        {
            HashSet <Vertex> changed = new HashSet <Vertex>();

            // update valves by querying physical interface
            foreach (Valve v in valves)
            {
                bool newState = physical.GetValveState(v.Row, v.PositionInRow);
                //Log.Debug("Pipes: Querying physical state of valve @ (row={0}, pos={1}) -> {2} (previous was {3})", v.row, v.position, newState, v.currentPhysicalState);
                if (v.currentPhysicalState != newState)
                {
                    v.currentPhysicalState = newState;
                    changed.Add(v);
                    Log.Verbose("Pipes: {0} state changed, now {1}", v, v.IsOpen ? "open" : "closed");
                }
            }

            // update fans by computing connections
            HashSet <Fan> fansToBeRunning = findCorrectlyConnectedFans();

            RunningFansCount = fansToBeRunning.Count;

            //Log.Debug("Updating fans.")
            // start newly connected fans
            foreach (Fan f in fansToBeRunning)
            {
                if (!f.IsRunning)
                {
                    f.IsRunning = true;
                    physical.SetFanState(f.Row, f.PositionInRow, true);
                    changed.Add(f);
                    Log.Verbose("Pipes: {0} state changed, now running", f);
                }
            }

            // stop newly unconnected fans
            foreach (Fan f in fans)
            {
                if (f.IsRunning && !fansToBeRunning.Contains(f))
                {
                    f.IsRunning = false;
                    physical.SetFanState(f.Row, f.PositionInRow, false);
                    changed.Add(f);
                    Log.Verbose("Pipes: {0} state changed, now stopped", f);
                }
            }

            //Debug.Log("Changed vertices: " + changed.ToString1());
            return(changed);
        }