// Adds the given child thoughtform.
 public void AddChild(Thoughtform child)
 {
     child.SetParent(this);
     children.Add(child);
 }
Exemple #2
0
    public void UpdateAction()
    {
        if (Time.time - lastDecision < decisionDelay) return;
        lastDecision = Time.time;

        switch (currentObjective)
        {
        case Objective.CaptureMegaliths:

            Debug.Log(entity + " objective is CaptureMegaliths");

            currentMegalith = NextMegalith();
            if (currentMegalith != null)
            {
                var toMegalith = entity.Position() - currentMegalith.Position();
                var distance = toMegalith.magnitude;
                Debug.Log(entity + " current megalith is " + currentMegalith);
                Debug.Log(entity + " distance to megalith is " + distance + "m");
                if (distance > 1000f)
                {
                    entity.target = currentMegalith;
                }
                else
                {
                    currentObjective = Objective.ConvertThoughtforms;
                    goto case Objective.ConvertThoughtforms;
                }
            }
            else
            {
                Debug.Log(entity + " has no megaliths to capture");
                currentObjective = Objective.ConvertEnemies;
                goto case Objective.ConvertEnemies;
            }
            break;

        case Objective.ConvertThoughtforms:

            Debug.Log(entity + " objective is ConvertThoughtforms");

            currentThoughtform = NextThoughtform(currentMegalith);
            if (currentThoughtform != null)
            {
                Debug.Log(entity + " current thoughtform is " + currentThoughtform);
                entity.target = currentThoughtform;
            }
            else
            {
                currentObjective = Objective.CaptureMegaliths;
                goto case Objective.CaptureMegaliths;
            }
            break;

        case Objective.ConvertEnemies:

            Debug.Log(entity + " objective is ConvertEnemies");

            var nextEnemy = NextEnemyNearby();
            if (nextEnemy != null)
            {
                if (entity.awareness.IsFriend(nextEnemy))
                {
                    Debug.Log(entity + " converted enemy " + nextEnemy);
                    entity.awareness.enemies.Remove(nextEnemy);
                    goto case Objective.ConvertEnemies;
                }
                else
                {
                    Debug.Log(entity + " next enemy is " + nextEnemy);
                    entity.target = nextEnemy;
                }
            }
            else
            {
                Debug.Log(entity + " finished with enemies");
                entity.target = null;
                currentObjective = Objective.CaptureMegaliths;
            }
            break;

        case Objective.ConvertThreats:

            Debug.Log(entity + " objective is ConvertThreats");

            var nextThreat = NextThreat();
            if (nextThreat != null)
            {
                if (!entity.awareness.IsFriend(nextThreat))
                {
                    Debug.Log(entity + " next threat is " + nextThreat);
                    entity.target = nextThreat;
                }
                else
                {
                    Debug.Log(entity + " neutralised threat " + nextThreat);
                    entity.awareness.threats.Remove(nextThreat);
                    goto case Objective.ConvertThreats;
                }
            }
            else
            {
                Debug.Log(entity + " finished with threats");
                entity.target = null;
                currentObjective = Objective.CaptureMegaliths;
            }
            break;

        }
    }