Beispiel #1
0
    public override void Inherit(Trait trait1, Trait trait2)
    {
        NumericalTrait nt1 = trait1 as NumericalTrait;
        NumericalTrait nt2 = trait2 as NumericalTrait;

        SetValue(Random.Range(nt1.floatValue, nt2.floatValue));
    }
Beispiel #2
0
    public void CalculateTraitAverages()
    {
        ArrayList _currentAgents = currentAgents;

        var traitSums = new Dictionary <string, TraitStatistic>();

        foreach (Agent agent in _currentAgents)
        {
            foreach (var pair in agent.Traits())
            {
                NumericalTrait trait = pair.Value as NumericalTrait;
                if (trait != null)
                {
                    TraitStatistic statistic;
                    if (!traitSums.TryGetValue(pair.Key, out statistic))
                    {
                        statistic = new TraitStatistic(pair.Key, 0, trait);
                    }
                    traitSums[pair.Key] = new TraitStatistic(pair.Key, statistic.floatValue + trait.floatValue, trait);
                }
            }
        }

        ArrayList newTraits = new ArrayList();

        foreach (KeyValuePair <string, TraitStatistic> pair in traitSums)
        {
            TraitStatistic statistic = pair.Value;
            statistic.floatValue = statistic.floatValue / _currentAgents.Count;
            newTraits.Add(statistic);
        }

        traitAverages     = newTraits;
        _needsTraitUpdate = false;
        _lastTraitUpdate  = Time.time;
    }
    void OnGUI()
    {
        if (!agent)
        {
            return;
        }

        GUI.skin = Manager().guiSkin;

        GUILayout.BeginArea(new Rect(Screen.width - 200 - 10, 10, 200, Screen.height - 10));

        GUILayout.BeginVertical("box");
        GUILayout.Label(agent.lastEventName);
        GUILayout.Label(agent.AIStateDescription());

        GUILayout.BeginHorizontal();
        Tab("Status");
        Tab("DNA");
        Tab("Food");
        Tab("Sex");
        GUILayout.EndHorizontal();


        if (TabContent("Status"))
        {
            GUILayout.Label("INFO");
            GUILayout.Label("Energy: " + FractionAndPercent(agent.energy, agent.body.MaxEnergy()));
            GUILayout.Label("Will starve in " + SimpleFloat(agent.body.TimeUntilStarvation()) + "s.");
            GUILayout.Label("Age: " + FractionAndPercent(agent.Age(), agent.body.Lifespan()));
            if (agent.reproductiveSystem.IsChild())
            {
                GUILayout.Label("Child for " + SimpleFloat(agent.reproductiveSystem.ChildLength() - agent.Age()) + "s");
            }
            else
            {
                GUILayout.Label("Adult");
            }
        }

        if (TabContent("DNA"))
        {
            GUILayout.Label("INHERITED TRAITS");
            foreach (var pair in agent.Traits())
            {
                NumericalTrait trait = pair.Value as NumericalTrait;
                if (trait != null)
                {
                    GUILayout.Label(pair.Key + ": " + SimpleFloat(trait.floatValue));
                }
            }

            GUILayout.Label("CALCULATED TRAITS");

            GUILayout.Label("Speed: " + SimpleFloat(agent.body.Speed()));
            GUILayout.Label("Strength: " + SimpleFloat(agent.body.Strength()));
            GUILayout.Label("EnergyDrainPerSecond: " + SimpleFloat(agent.body.EnergyDrainPerSecond()));
            GUILayout.Label("MaxEnergy: " + SimpleFloat(agent.body.MaxEnergy()));
            GUILayout.Label("CamouflageFactor: " + agent.body.CamouflageFactor());
        }

        if (TabContent("Food"))
        {
            GUILayout.Label("Meals eaten: " + agent.hungerCenter.timesEaten);

            GUILayout.Label("Herbivore: " + agent.hungerCenter.herbivore.boolValue);
            GUILayout.Label("Hay eaten: " + agent.hungerCenter.timesEatenVeg);

            GUILayout.Label("Carnivore: " + agent.hungerCenter.herbivore.boolValue);
            GUILayout.Label("Meat eaten: " + agent.hungerCenter.timesEatenMeat);
        }

        //DrawProgressBar(new Rect(0, 0, 200, 16), agent.energy / agent.body.MaxEnergy());

        if (TabContent("Sex"))
        {
            GUILayout.Label("Generation: " + agent.reproductiveSystem.generation);
            GUILayout.Label("Times reproduced: " + agent.reproductiveSystem.timesReproduced);

            GUILayout.Label("PARENTS");
            Agent[] parents = agent.reproductiveSystem.parents;
            if (parents != null)
            {
                int i = 1;
                foreach (Agent parent in parents)
                {
                    if (GUILayout.Button("Select Parent " + i + " (Gen " + parent.reproductiveSystem.generation + ")"))
                    {
                        Manager().SelectAgent(parent);
                    }
                    i++;
                }
            }
            if (parents == null || parents.Length < 1)
            {
                GUILayout.Label("No parents");
            }

            GUILayout.Label("CHILDREN");
            // Agent[] children = agent.reproductiveSystem.children;
            // if (children == null || children.Length < 1) {
            //   GUILayout.Label("No children");
            // }
        }

        GUILayout.EndVertical();
        GUILayout.EndArea();
    }