public bool Matches(MoleculeDefinition other)
        {
            if (atoms.Count != other.atoms.Count || bonds.Count != other.bonds.Count)
            {
                return(false);
            }
            Dictionary <Vector2i, AtomDefinition> dictionary1 = ToAtomDefinitions(this);
            Dictionary <Vector2i, AtomDefinition> dictionary2 = ToAtomDefinitions(other);
            // Pre-allocating the undo stack is just an optimization. Every time MoleculeMatchesRecursive()
            // returns false, it restores the stack to its initial state, so it's safe to reuse
            // the same object instead of allocating new ones for each call. We quit when
            // MoleculeMatchesRecursive() returns true, so we don't care about whatever is left there in that case.
            List <AtomDefinition> undoStack = new List <AtomDefinition>(atoms.Count * 2);

            foreach (AtomDefinition atomDefinition1 in dictionary1.Values)
            {
                foreach (AtomDefinition atomDefinition2 in dictionary2.Values)
                {
                    if (MoleculeMatchesRecursive(atomDefinition1, atomDefinition2, undoStack))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        public static void DoSwap(Reactor reactor, bool forRed)
        {
            List <QuantumTunnelFeature> allTunnels;
            List <Vector2i>             tunnelPositions;

            CollectTunnels(reactor, out allTunnels, out tunnelPositions);
            int tunnelCount = allTunnels.Count;

            if (tunnelCount == 0)
            {
                return;
            }
            List <Optional <MoleculeDefinition> > removedAtoms = new List <Optional <MoleculeDefinition> >();

            for (int i = 0; i < tunnelCount; i++)
            {
                removedAtoms.Add(TearOutAtomOnTunnel(reactor, tunnelPositions[i]));
            }
            // repeat the first element at the end to simplify roll-around logic
            allTunnels.Add(allTunnels[0]);
            tunnelPositions.Add(tunnelPositions[0]);
            for (int i = 0; i < tunnelCount; i++)
            {
                if (removedAtoms[i].isPresent)
                {
                    MoleculeDefinition atomToMove = removedAtoms[i].GetValue();
                    atomToMove.Translate(tunnelPositions[i + 1]);
                    reactor.moleculeList.Add(new Molecule(atomToMove, reactor));
                    allTunnels[i].laserState = 0.0f;
                    allTunnels[i].Activate(forRed);
                    // we hijack the already existing boolean field for storing whether
                    // the laser is activated for red, and use a new injected field
                    // for storing the same thing for the sensor
                    allTunnels[i].isActivatedForRed     = forRed;
                    allTunnels[i + 1].sensorCircleState = 0.0f;
                    allTunnels[i + 1].Activate(forRed);
                    allTunnels[i + 1].isSensorActivatedForRed = forRed;
                }
            }
            foreach (Waldo waldo in reactor.waldos.Values)
            {
                if (waldo.molecule != null)
                {
                    waldo.Drop();
                    waldo.Grab();
                }
            }
        }
 private static Dictionary <Vector2i, AtomDefinition> ToAtomDefinitions(MoleculeDefinition moleculeDefinition)
 {
     return(null);
 }
 public static IEnumerable <MoleculeDefinition> BreakBond(MoleculeDefinition moleculeDefinition, PotentialBond bondToRemove)
 {
     return(null);
 }
 public void CopyAtomsAndBonds(MoleculeDefinition source)
 {
 }
 public static void DoBond(BondType bondType, Reactor reactor, bool forRed)
 {
     foreach (PotentialBond potentialBond in GetPotentialBonds(reactor, bondType))
     {
         Molecule molecule1 = reactor.moleculeList.getMoleculeAtCoords(potentialBond.coords);
         Molecule molecule2 = reactor.moleculeList.getMoleculeAtCoords(potentialBond.getCoordsOfOtherBonder());
         if (molecule1 != null && molecule2 != null)
         {
             MoleculeDefinition resultMolecule = molecule1.GetTransformedDefinition(Vector2i.NULL);
             if (bondType == BondType.Plus)
             {
                 if (molecule1 != molecule2)
                 {
                     resultMolecule.CopyAtomsAndBonds(molecule2.GetTransformedDefinition(Vector2i.NULL));
                 }
                 BondCount numBonds = (BondCount)1;
                 // Math.Min(atom.bondCount(potentialBond).Value + 1, 3)
                 // aka increase bonds by 1 but not more than 3
                 if (resultMolecule.GetBondCount(potentialBond).HasValue)
                 {
                     numBonds = (BondCount)Math.Min((int)(resultMolecule.GetBondCount(potentialBond).Value + 1), 3);
                 }
                 if (resultMolecule.SetBondCountWithMaxBondsCheck(potentialBond, numBonds))
                 {
                     reactor.moleculeList.Remove(molecule1);
                     if (molecule1 != molecule2)
                     {
                         reactor.moleculeList.Remove(molecule2);
                     }
                     reactor.moleculeList.Add(new Molecule(resultMolecule, reactor));
                     reactor.AddBondEffect((potentialBond.coords + potentialBond.getCoordsOfOtherBonder()) * 0.5f, BondEffectStyle.Plus, forRed);
                 }
                 else
                 {
                     reactor.AddBondEffect((potentialBond.coords + potentialBond.getCoordsOfOtherBonder()) * 0.5f, BondEffectStyle.MaxBonds, forRed);
                     // The next line is the only change in this method, and should fix the telekinesis bug.
                     // If both waldos hold the same molecule and we allow execution to continue to the next foreach,
                     // the following would happen:
                     // 1. The pull vectors of the molecule are cleared.
                     // 2. The red waldo adds itself to the molecule's pull vectors in GrabDrop().
                     // 3. The pull vectors of the molecule are cleared _again_, removing the red waldo.
                     // 4. The blue waldo adds itself to the molecule's pull vectors in GrabDrop().
                     // The end result is that the game thinks only blue is holding the molecule, triggering the telekinesis bug.
                     // It's safe to skip this foreach since hitting max bonds means no molecule was changed and the current pull vectors are still OK.
                     continue;
                 }
             }
             // bondType != BondType.Plus
             else if (molecule1 == molecule2 && resultMolecule.GetBondCount(potentialBond).HasValue)
             {
                 reactor.moleculeList.Remove(molecule1);
                 int newBondCount = (int)(resultMolecule.GetBondCount(potentialBond).Value - 1);
                 if (newBondCount < 1)
                 {
                     foreach (MoleculeDefinition newMolecule in MoleculeDefinition.BreakBond(resultMolecule, potentialBond))
                     {
                         reactor.moleculeList.Add(new Molecule(newMolecule, reactor));
                     }
                 }
                 else
                 {
                     resultMolecule.SetBondCount(potentialBond, new BondCount?((BondCount)newBondCount));
                     reactor.moleculeList.Add(new Molecule(resultMolecule, reactor));
                 }
                 reactor.AddBondEffect((potentialBond.coords + potentialBond.getCoordsOfOtherBonder()) * 0.5f, BondEffectStyle.Minus, forRed);
             }
             else
             {
                 continue;
             }
             foreach (Waldo waldo in reactor.waldos.Values)
             {
                 if (waldo.molecule != null)
                 {
                     waldo.molecule.WaldoPullVectors.Clear();
                     waldo.molecule = null;
                     waldo.GrabDrop();
                 }
             }
         }
     }
     if (isBonderFeatureCache == null)
     {
         isBonderFeatureCache = new Func <ReactorMember, bool>(IsBonderFeature);
     }
     foreach (BonderFeature bonderFeature in reactor.GetMembers().Where(isBonderFeatureCache).Cast <BonderFeature>())
     {
         bonderFeature.Activate(forRed);
     }
 }
 public MoleculeBuilder(bool bool1, bool bool2, MoleculeDefinition molecule, Action <MoleculeDefinition> action, bool showGreek, Original dummy)
 {
 }
 public MoleculeBuilder(bool bool1, bool bool2, MoleculeDefinition molecule, Action <MoleculeDefinition> action, bool showGreek = false)
     : this(bool1, bool2, molecule, action, true, Original.INSTANCE)
 {
 }
Beispiel #9
0
 public Molecule(MoleculeDefinition definition, Reactor reactor)
 {
 }
 public static void AddOutputCargoFreighter40(MoleculeDefinition molecule, DraggableContainer container, Vector2i position)
 {
 }