protected override TreeViewItem BuildRoot() { AITreeItem root = new AITreeItem(); IReadonlyListX <BehaviorSet> behaviorSets = db.GetAssetList <BehaviorSet>(); foreach (BehaviorSet behaviorSet in behaviorSets) { AITreeItem behaviorSetItem = new AITreeItem(behaviorSet); root.AddChild(behaviorSetItem); // foreach (BehaviorDefinition behaviorDefinition in behaviorSet.behaviors) { // // AITreeItem behaviorItem = new AITreeItem(behaviorDefinition); // behaviorSetItem.AddChild(behaviorItem); // // foreach (ActionDefinition action in behaviorDefinition.actions) { // behaviorItem.AddChild(new AITreeItem(action)); // } // // } } if (root.children == null) { root.children = new List <TreeViewItem>(); } SetupDepthsFromParentsAndChildren(root); return(root); }
public void DecideGoalBehavior() { lastBehaviorDecision = GameTimer.Instance.GetFrameTimestamp(); IReadonlyListX <DecisionContext> goalContexts = activeGoal.GetExecutionContexts(entity); float maxScore = float.MinValue; activeContext = null; activeBehavior = null; for (int i = 0; i < behaviors.Count; i++) { AIBehavior behavior = behaviors[i]; if (!behavior.CanSatisfyGoalType(activeGoal.goalType)) { // continue; } DecisionContext context; float score = AIUtil.Score(goalContexts, behavior.considerations, maxScore, out context); if (score > maxScore) { maxScore = score; activeBehavior = behavior; activeContext = context; } } }
protected override TreeViewItem BuildRoot() { TreeViewItem root = new TreeViewItem(-9999, -1); IReadonlyListX <ShipTypeGroup> shipTypes = GameDatabase.ActiveInstance.GetAssetList <ShipTypeGroup>(); for (int i = 0; i < shipTypes.Count; i++) { ShipTypeGroupItem item = new ShipTypeGroupItem(i, shipTypes[i]); root.AddChild(item); if (shipTypes[i].ships == null) { shipTypes[i].ships = new List <ShipType>(); } for (int j = 0; j < shipTypes[i].ships.Count; j++) { ShipType shipType = shipTypes[i].ships[j]; item.AddChild(new ShipTypeItem(j, shipType)); } } if (root.children == null) { root.children = new List <TreeViewItem>(); } SetupDepthsFromParentsAndChildren(root); return(root); }
/* * Todo -- Figure out Chassis handling w/ ids and ship types * Todo -- Figure out weapons loadout w/ ship type / chassis * Todo -- Change GameDatabase to initialize on load and handle what mission window handles right now * Todo -- Multiple save files / locations in case we f**k up * Todo -- Name generator from Faction / Flight Group * Todo -- Allow Template Entity Definitions, mark appropriately * Todo -- Index hierarchy lists w/ dictionaries instead of n ^ 3 search */ private void SetShipTypeFromChassis(Entity sceneEntity, EntityDefinition entityDefinition) { Chassis chassis = sceneEntity.GetComponentInChildren <Chassis>(); GameObject chassisGameObject = chassis?.gameObject; if (chassisGameObject == null) { return; } Object prefabRoot = PrefabUtility.GetPrefabParent(chassisGameObject); string path = AssetDatabase.GetAssetPath(prefabRoot); Debug.Log(path); path = path.Replace("Assets/Resources/", ""); Debug.Log(path); // todo -- chassis needs an id! its possible to have 2 ship types w/ the same chassis asset IReadonlyListX <ShipType> shipTypes = shipTypeAssetMap.GetList(); for (int i = 0; i < shipTypes.Count; i++) { ShipType shipType = shipTypes[i]; if (shipType.chassis.assetPath == path) { Debug.Log("Found it"); return; } } Debug.Log("Nope"); }
private void CreateMenu(object sender, AddMenuClickedEventArgs args) { GameDatabase db = GameDatabase.ActiveInstance; IReadonlyListX <BehaviorSet> behaviorSets = db.GetAssetList <BehaviorSet>(); GenericMenu menu = new GenericMenu(); for (int i = 0; i < behaviorSets.Count; i++) { GUIContent content = new GUIContent($"Add {behaviorSets[i].name}"); BehaviorSet bs = behaviorSets[i]; menu.AddItem(content, false, () => { propertyAsList.AddElement(bs); }); } menu.ShowAsContext(); }
public static float Score(IReadonlyListX <DecisionContext> contexts, Consideration[] considerations, float cutoff, out DecisionContext outputContext) { int length = contexts.Count; int considerationCount = considerations.Length; float modFactor = 1f - (1f / considerationCount); float maxScore = float.MinValue; outputContext = null; DecisionContext[] rawList = contexts.RawArray; for (int i = 0; i < length; i++) { DecisionContext context = rawList[i]; float finalScore = 1 + 0; //todo -- bonus / personality influence for (int j = 0; j < considerationCount; j++) { if (finalScore < 0 || finalScore < cutoff) { break; } Consideration consideration = considerations[j]; UnityEngine.Debug.Assert(consideration != null, nameof(consideration) + " != null"); float score = consideration.curve.Evaluate(consideration.Score(context)); float makeUpValue = (1f - score) * modFactor; float total = score + (makeUpValue * score); finalScore *= MathUtil.Clamp01(total); } if (finalScore > maxScore) { maxScore = finalScore; outputContext = context; } } return(maxScore); }
public void DecideGoal() { lastGoalDecision = GameTimer.Instance.GetFrameTimestamp(); float maxScore = float.MinValue; activeGoal = null; for (int i = 0; i < goals.Count; i++) { Goal goal = goals[i]; if ((behaviorCompatibiltyFlags & (int)goal.goalType) == 0) { // continue; } DecisionContext unused_bestContext; IReadonlyListX <DecisionContext> contexts = goal.GetEvaluationContexts(entity); float score = AIUtil.Score(contexts, goal.considerations, maxScore, out unused_bestContext); // todo personality skew the score if (score > maxScore) { maxScore = score; activeGoal = goal; } } }