// Use this for initialization void Start() { //set the game manager nodeManager = GameObject.Find("GameManager").GetComponent <NodeManager>(); if (!nodeManager) { Debug.LogError("cannot locate node manager"); } //set the knowledge base knowledgeBase = gameObject.GetComponent <NodeKnowledgeBase>(); if (!knowledgeBase) { Debug.LogError("no knowledge base attached to " + gameObject.name); } listSize = needList.Count; for (int i = 0; i < needList.Count; i++) { if (!needList[i].Init()) { Debug.Log("Error on element : " + i + " On object : " + gameObject.name); } else { Debug.Log(i + " : No errors"); } } //add needs to the UI script (if there is one attached) if (gameObject.GetComponentInChildren <NeedsUIScript>()) { gameObject.GetComponentInChildren <NeedsUIScript>().addToList(); } if (gameObject.GetComponentInChildren <WeightUIScript>()) { gameObject.GetComponentInChildren <WeightUIScript>().addToList(); } oldPosition = gameObject.transform.position; //default state state = currentState.none; }
static NodeFactory() { _dicTemplates = new Dictionary <TokenType, List <NodeTemplate> >(); NodeKnowledgeBase.LoadKnowledge(); }
public int GetHighestWeight(List <NeedsBase> needList, GameObject parentObjectInput) { //set the parent parentObject = parentObjectInput; //if the knowledgebase isn't set, go get it if (!knowledgeBase) { knowledgeBase = parentObject.GetComponent <NodeKnowledgeBase>(); } //calculate current weights for (int i = 0; i < needList.Count; i++) { needList[i].setWeight(CalculateWeight(needList[i])); } //temp values for comparison of weights and sotring of index float currentHighestWeight = needList[0].GetWeight(); int highestWeightIndex = 0; int secondHighestWeightIndex = 0; //once all weights are calculated, get the highest one for (int i = 0; i < needList.Count; i++) { //exempt any needs that do not have a known node //if this weight is higher than the current highest weight, replace it if (needList[i].GetWeight() > currentHighestWeight) { currentHighestWeight = needList[i].GetWeight(); highestWeightIndex = i; } } //zero the current highest value (Index is already saved) currentHighestWeight = 0.0f; //now get the second highest weight for (int i = 0; i < needList.Count; i++) { //exempt any needs that do not have a known node if (needList[i].GetWeight() > currentHighestWeight && needList[i].GetWeight() < needList[highestWeightIndex].GetWeight()) { currentHighestWeight = needList[i].GetWeight(); secondHighestWeightIndex = i; } } //check if the two are the same if (highestWeightIndex == secondHighestWeightIndex) { //FIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXITFIXIT float weight = needList[highestWeightIndex].GetWeight(); weight += 0.1f; //reset the weight with a slight adjustment to break any deadlocks needList[highestWeightIndex].setWeight(weight); } //Debug.Log(needList[highestWeightIndex].needName + " is the highest weight"); return(highestWeightIndex); }