protected void CopyTo(ProgrammingElement clone) { base.CopyTo(clone); clone.hiddenDefault = this.hiddenDefault; clone.group = this.group; clone.groupObj = this.groupObj; clone.helpGroups = this.helpGroups; clone.archived = this.archived; clone.mountkey = this.mountkey; clone.mountlock = this.mountlock; clone.XmlCategories = this.XmlCategories; clone.XmlInclusions = this.XmlInclusions; clone.XmlExclusions = this.XmlExclusions; clone.XmlNegations = this.XmlNegations; clone.XmlInputs = this.XmlInputs; clone.XmlNegOutputs = this.XmlNegOutputs; clone.XmlArchivedInclusions = this.XmlArchivedInclusions; clone.categories = this.categories; clone.inclusions = this.inclusions; clone.exclusions = this.exclusions; clone.negations = this.negations; clone.inputs = this.inputs; clone.negOutputs = this.negOutputs; clone.archivedInclusions = this.archivedInclusions; clone.categoryCount = this.categoryCount; clone.exclusionCount = this.exclusionCount; clone.inclusionCount = this.inclusionCount; clone.negationCount = this.negationCount; clone.inputCount = this.inputCount; clone.negOutputCount = this.negOutputCount; clone.archivedInclusionCount = this.archivedInclusionCount; clone.MaxInstanceCount = this.MaxInstanceCount; clone.MaxClassCount = this.MaxClassCount; }
private float RankElements(ProgrammingElement a, ProgrammingElement b, float scorage) { float rank = 0.0f; if (a != null && b != null) { if (a.upid == b.upid) { rank += scorage; } if (a.helpGroups != null && b.helpGroups != null) { for (int i = 0; i < a.helpGroups.Length; ++i) { for (int j = 0; j < b.helpGroups.Length; ++j) { if (a.helpGroups[i] == b.helpGroups[j]) { rank += scorage / 2; } } } } } return(rank); }
public override bool ReflexCompatible(ReflexData clip, ProgrammingElement replacedElement) { bool compatible = false; Actuator actuator = clip.Actuator; Sensor sensor = clip.Sensor; if (actuator != null && sensor != null) { Actuator.Category category = Actuator.Category.Direction | Actuator.Category.TargetlessDirection; if ((actuator.category & category) != 0 && (sensor.category & Sensor.Category.GamePad) != 0) { compatible = true; // check the filters for compatibility against our type for (int indexFilter = 0; indexFilter < clip.Filters.Count; indexFilter++) { Filter filter = clip.Filters[indexFilter] as Filter; if (filter != null) { if (!filter.ElementCompatible(clip, this)) { compatible = false; break; } } } } } return(compatible); }
/// <summary> /// Rank and sort the set of examples relevant to the provided actor, reflex, /// and selection. /// </summary> /// <param name="actor">Optional</param> /// <param name="reflex">Required</param> /// <param name="selected">Optional</param> public static void RankAndSortProgrammingExamples( GameActor actor, ReflexData reflex, ProgrammingElement selected) { Debug.Assert(reflex != null, "The reflex argument must not be null."); instance.InternalRankAndSortProgrammingExamples(actor, reflex, selected); }
public override bool ReflexCompatible(GameActor actor, ReflexData reflex, ProgrammingElement replacedElement, bool allowArchivedCategories) { // An actuator must exist before any modifiers may appear. if (reflex.Actuator == null || reflex.Actuator is NullActuator) { return(false); } // Check compatibility with actor. { if (!this.ActorCompatible(actor)) { return(false); } } // Check modifier instance count { string selectionUpid = (replacedElement != null) ? replacedElement.upid : null; int instanceCount = reflex.GetModifierCount(this.upid); // Don't consider the selected one if it's of our type, since we'd be replacing it. if (selectionUpid == this.upid) { instanceCount -= 1; } if (instanceCount >= this.MaxInstanceCount) { return(false); } } // Check modifier class count { Type selectionType = (replacedElement != null) ? replacedElement.GetType() : null; int count = reflex.GetModifierCountByType(this.GetType()); // Don't consider the selected one if it's of our type, since we'd be replacing it. if (selectionType == this.GetType()) { count -= 1; } if (count >= this.MaxClassCount) { return(false); } } return(base.ReflexCompatible(actor, reflex, replacedElement, allowArchivedCategories)); }
/// <summary> /// Check if this programming element is compatible with the other element /// This is often used by other other elements from within their ReflexCompatible /// </summary> /// <param name="other">other elemement to check</param> /// <returns>true if compatible</returns> public bool ElementCompatible(ProgrammingElement other) { if (this.InclusionCount > 0 && !other.MatchesAnyCategory(this.Inclusions)) { return(false); } if (this.ExclusionCount > 0 && other.MatchesAnyCategory(this.Exclusions)) { return(false); } return(true); }
private void InternalRankAndSortProgrammingExamples( GameActor actor, ReflexData reflex, ProgrammingElement selected) { RankSettings settings = new RankSettings(); settings.sensorRank = 2; settings.selectorRank = 2; settings.filterRank = 2; settings.actuatorRank = 2; settings.modifierRank = 2; settings.otherFilterRank = 1; settings.otherModifierRank = 1; if (selected is Filter) { settings.filterRank = 10; } else if (selected is Actuator) { settings.actuatorRank = 10; } else if (selected is Modifier) { settings.modifierRank = 10; } else if (selected is Selector) { settings.selectorRank = 10; } else if (selected is Sensor) { settings.sensorRank = 10; } RankAndSortProgrammingExamples( settings, actor, selected, reflex ); }
private void RankAndSortProgrammingExamples( RankSettings settings, GameActor actor, ProgrammingElement selected, ReflexData reflex) { for (int i = 0; i < programmingExamples.Count; ++i) { ExamplePage example = programmingExamples[i]; RankProgrammingExample( example, settings, actor, selected, reflex); } programmingExamples.Sort(CompareByRank); }
/// <summary> /// Check if this selector is compatible within the given reflex and replacing the given element /// </summary> /// <param name="reflex">reflex to check if it works within</param> /// <param name="replacedElement">optional, if provided this will replace it</param> /// <returns>true if compatible</returns> public override bool ReflexCompatible(GameActor actor, ReflexData reflex, ProgrammingElement replacedElement, bool allowArchivedCategories) { // Actuator must exist { if (reflex.Actuator == null || reflex.Actuator is NullActuator) { return(false); } } // Check actuator compatibility { if (!this.ElementCompatible(reflex.Actuator)) { return(false); } } return(base.ReflexCompatible(actor, reflex, replacedElement, allowArchivedCategories)); }
public virtual bool ReflexCompatible(GameActor actor, ReflexData reflex, ProgrammingElement replacedElement, bool allowArchivedCategories) { // Check actor compatibility { if (!this.ActorCompatible(actor)) { return(false); } } // Build datatype bitmask { string selectionUpid = (replacedElement != null) ? replacedElement.upid : null; scratchOutputs.SetAll(false); scratchNegOutputs.SetAll(false); // Set sensor bits if (reflex.Sensor != null) { scratchOutputs.Or(reflex.Sensor.Outputs); } else { // if no sensor, simulate a boolean output type (for "always" behavior). scratchOutputs.Set((int)SensorOutputType.Boolean, true); } // Set filter bits foreach (Filter filter in reflex.Filters) { // Don't consider the selected one, since we'd be replacing it. if (filter.upid == selectionUpid) { selectionUpid = null; continue; } scratchOutputs.Or(filter.Outputs); scratchNegOutputs.Or(filter.NegOutputs); } // Set actuator bits if (reflex.Actuator != null) { scratchNegOutputs.Or(reflex.Actuator.NegOutputs); } // Set selector bits if (reflex.Selector != null) { scratchNegOutputs.Or(reflex.Selector.NegOutputs); } // Set modifier bits foreach (Modifier modifier in reflex.Modifiers) { // Don't consider the selected one, since we'd be replacing it. if (modifier.upid == selectionUpid) { selectionUpid = null; continue; } scratchNegOutputs.Or(modifier.NegOutputs); } } // If this element is on the do side, remove negated outputs. // TODO (****) I just noticed that "this is Filter" is here even though filters // shouldn't be on the DO side. Is this a bug or do we need this? if (this is Actuator || this is Selector || this is Modifier || this is Filter) { scratchOutputs.And(scratchNegOutputs.Not()); } // Check datatype compatibility { if (this.InputCount > 0 && !MatchesAnyBit(scratchOutputs, this.Inputs)) { return(false); } } // Build category bitmask int scratchExclusionCount = 0; { string selectionUpid = (replacedElement != null) ? replacedElement.upid : null; scratchCategories.SetAll(false); scratchNegations.SetAll(false); // Set sensor bits if (reflex.Sensor != null && reflex.Sensor.upid != selectionUpid) { scratchCategories.Or(reflex.Sensor.Categories); scratchNegations.Or(reflex.Sensor.Negations); } // Set actuator bits if (reflex.Actuator != null && reflex.Actuator.upid != selectionUpid) { scratchCategories.Or(reflex.Actuator.Categories); scratchNegations.Or(reflex.Actuator.Negations); } // Set selector bits if (reflex.Selector != null && reflex.Selector.upid != selectionUpid) { scratchCategories.Or(reflex.Selector.Categories); scratchNegations.Or(reflex.Selector.Negations); } // Set filter bits foreach (Filter filter in reflex.Filters) { // Don't consider the selected modifier, since we'd be replacing it. // Don't consider any filters after the selection either, since we need to consider only everything to its left when replacing. if (filter.upid == selectionUpid) { selectionUpid = null; break; } scratchCategories.Or(filter.Categories); scratchNegations.Or(filter.Negations); scratchExclusionCount += Math.Max(scratchExclusionCount, filter.ExclusionCount); } // Set modifier bits foreach (Modifier modifier in reflex.Modifiers) { // Don't consider the selected modifier, since we'd be replacing it. // Don't consider any modifiers after the selection either, since we need to consider only everything to its left when replacing. if (modifier.upid == selectionUpid) { selectionUpid = null; break; } scratchCategories.Or(modifier.Categories); scratchNegations.Or(modifier.Negations); scratchExclusionCount = Math.Max(scratchExclusionCount, modifier.ExclusionCount); } } // If this element is on the "do" side, remove negated categories. // Let Negations work on WHEN side also... //if (this is Actuator || this is Selector || this is Modifier) { scratchNegations.Not(); // Invert the negations. scratchCategories.And(scratchNegations); } // Build my inclusion bitmask { scratchMyCategories.SetAll(false); scratchMyCategories.Or(this.Inclusions); if (allowArchivedCategories) { scratchMyCategories.Or(this.ArchivedInclusions); } } #if DEBUG_COMPATIBILITY if (this.upid == "modifier.it") { scratchNegations.Not(); // Restore negations so they dump correctly. num++; Debug.Print(num.ToString()); Debug.Print(this.upid); DumpCategories(this.Inclusions, " inclusions"); DumpCategories(this.Exclusions, " exclusions"); DumpCategories(scratchCategories, " scratch"); DumpCategories(scratchMyCategories, " scratchMy"); DumpCategories(scratchNegations, " scratchNegations"); } #endif // Check category compatibility { if (this.InclusionCount > 0 && !MatchesAnyBit(scratchCategories, scratchMyCategories)) { return(false); } if (this.ExclusionCount > 0 && MatchesAnyBit(scratchCategories, this.Exclusions)) { return(false); } } return(true); }
/// <summary> /// Check if this programming element is compatible within the given reflex and optionally replacing the given element /// </summary> /// <param name="reflex">reflex to check if it works within</param> /// <param name="replacedElement">optional, if provided this will replace it</param> /// <returns>true if compatible</returns> public bool ReflexCompatible(Reflex reflex, ProgrammingElement replacedElement, bool allowArchivedCategories) { return(ReflexCompatible(reflex.Task.Brain.GameActor, reflex.Data, replacedElement, allowArchivedCategories)); }
private void RankProgrammingExample( ExamplePage example, RankSettings settings, GameActor actor, ProgrammingElement selected, ReflexData reflex) { if (!example.ActorCompatible(actor)) { example.rank = -1; return; } string selectedUpid; if (selected != null) { selectedUpid = selected.upid; } else { selectedUpid = String.Empty; } example.rank = 0; for (int iReflex = 0; iReflex < example.reflexes.Length; ++iReflex) { ReflexData exampleReflex = example.reflexes[iReflex]; // Rank sensor if (selected == exampleReflex.Sensor) { example.rank += RankElements(exampleReflex.Sensor, selected, settings.sensorRank); } if (exampleReflex.Sensor != null && reflex.Sensor != null) { example.rank += RankElements(exampleReflex.Sensor, reflex.Sensor, settings.sensorRank); } // Rank selector if (selected == exampleReflex.Selector) { example.rank += RankElements(exampleReflex.Selector, selected, settings.selectorRank); } if (exampleReflex.Selector != null && reflex.Selector != null) { example.rank += RankElements(exampleReflex.Selector, reflex.Selector, settings.selectorRank); } // Rank actuator if (selected == exampleReflex.Actuator) { example.rank += RankElements(exampleReflex.Actuator, selected, settings.actuatorRank); } if (exampleReflex.Actuator != null && reflex.Actuator != null) { example.rank += RankElements(exampleReflex.Actuator, reflex.Actuator, settings.actuatorRank); } // Rank filters for (int i = 0; i < exampleReflex.Filters.Count; ++i) { if (selected == exampleReflex.Filters[i]) { example.rank += RankElements(exampleReflex.Filters[i], selected, settings.filterRank); } for (int j = 0; j < reflex.Filters.Count; ++j) { example.rank += RankElements(exampleReflex.Filters[i], reflex.Filters[j], settings.filterRank); } } // Rank modifiers for (int i = 0; i < exampleReflex.Modifiers.Count; ++i) { if (selected == exampleReflex.Modifiers[i]) { example.rank += RankElements(exampleReflex.Modifiers[i], selected, settings.modifierRank); } for (int j = 0; j < reflex.Modifiers.Count; ++j) { example.rank += RankElements(exampleReflex.Modifiers[i], reflex.Modifiers[j], settings.modifierRank); } } } }