/// <summary> /// Initializes a new instance of the /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RightStatement"/> class. /// </summary> /// <param name="reader">Reader.</param> public RightStatement(FileIOManager reader) { string nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, RightStatementOperation.Name)) { this.rightStatementOperation = new RightStatementOperation(reader); } else if (CommonHelperMethods.StringStartsWith(nextLine, ReadOnlyVariable.Name)) { this.readOnlyVariable = new ReadOnlyVariable(reader); } else if (CommonHelperMethods.StringStartsWith(nextLine, RightMethodCall.Name)) { this.rightMethodCall = new RightMethodCall(reader); } else if (CommonHelperMethods.StringStartsWith(nextLine, LiteralValue.Name)) { this.literalValue = new LiteralValue(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, new List <string>() { RightStatementOperation.Name, ReadOnlyVariable.Name, RightMethodCall.Name }); } }
/// <summary> /// Will possibly mutate this section of logic. /// </summary> public void PossiblyMutate() { if (GeneticLogicRoot.RollMutateDice()) { OperatorSignature signature; if (RegistrationManager.TrySelectOperatorAtRandom(this.ReturnType, out signature)) { this.rightStatementOperation = new RightStatementOperation(signature); this.readOnlyVariable = null; this.rightMethodCall = null; this.literalValue = null; return; } } if (GeneticLogicRoot.RollMutateDice()) { VariableSignature signature; if (RegistrationManager.TrySelectReadOnlyVariableAtRandom(this.ReturnType, out signature)) { this.rightStatementOperation = null; this.readOnlyVariable = new ReadOnlyVariable(signature); this.rightMethodCall = null; this.literalValue = null; return; } } if (GeneticLogicRoot.RollMutateDice()) { MethodSignature signature; if (RegistrationManager.TrySelectRightMethodAtRandom(this.ReturnType, out signature)) { this.rightStatementOperation = null; this.readOnlyVariable = null; this.rightMethodCall = new RightMethodCall(signature); this.literalValue = null; return; } } if (GeneticLogicRoot.RollMutateDice()) { // Create the new literal value first so ReturnType get doesn't reutrn null this.literalValue = new LiteralValue(this.ReturnType); this.rightStatementOperation = null; this.readOnlyVariable = null; this.rightMethodCall = null; return; } if (this.rightStatementOperation != null) { this.rightStatementOperation.PossiblyMutate(); } }
/// <summary> /// Initializes a new instance of the /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RightStatement"/> class. /// </summary> /// <param name="returnType">Return type.</param> public RightStatement(Type returnType) { if (returnType == null) { LogUtility.LogError("Cannot create right statement with null return type"); } double nextDouble = CommonHelperMethods.GetRandomDouble0To1(); if (nextDouble < 0.25) { OperatorSignature signature; if (RegistrationManager.TrySelectOperatorAtRandom(returnType, out signature)) { this.rightStatementOperation = new RightStatementOperation(signature); return; } } if (nextDouble < 0.5) { VariableSignature signature; if (RegistrationManager.TrySelectReadOnlyVariableAtRandom(returnType, out signature)) { this.readOnlyVariable = new ReadOnlyVariable(signature); return; } } if (nextDouble < 0.75) { MethodSignature signature; if (RegistrationManager.TrySelectRightMethodAtRandom(returnType, out signature)) { this.rightMethodCall = new RightMethodCall(signature); return; } } // Every GeneticType should support generation of a random literal value this.literalValue = new LiteralValue(returnType); }