Exemplo n.º 1
0
    public void SetMaxAndCurrent(Nutrients nutrient, int max)
    {
        MediaNutrient mediaNutrient = GetNutrient(nutrient, true);

        mediaNutrient.SetMax(max);
        mediaNutrient.Saturate();
    }
Exemplo n.º 2
0
 public void CopyMax(NutrientState media)
 {
     for (int i = 0, l = media.nutrients.Count; i < l; i++)
     {
         MediaNutrient template = media.nutrients[i];
         MediaNutrient target   = GetNutrient(template.nutrient, true);
         target.SetMax(template.MaxValue);
     }
 }
Exemplo n.º 3
0
 int GetExtractionVolume(MediaNutrient nutrient, int energy)
 {
     if (nutrient == null)
     {
         Debug.LogError("Nutrient is null");
         return(0);
     }
     Debug.Log(string.Format("using e {0} from saturation {1} capped by {2}", energy, nutrient.saturation, nutrient.CurrentValue));
     return(Mathf.FloorToInt(Mathf.Min(energy * nutrient.saturation, nutrient.CurrentValue)));
 }
Exemplo n.º 4
0
    public int Extract(Nutrients nutrient, int energy)
    {
        MediaNutrient mediaNutrient = GetNutrient(nutrient);

        if (mediaNutrient == null)
        {
            Debug.LogError(nutrient + " does not exist");
            return(0);
        }
        int extraction = GetExtractionVolume(mediaNutrient, energy);

        Debug.Log("Extractin " + extraction);
        return(mediaNutrient.Extract(extraction));
    }
Exemplo n.º 5
0
    void MakeWaste()
    {
        MediaNutrient C = GetNutrient(Nutrients.C);

        data.waste += C.Extract(C.CurrentValue / 4);

        MediaNutrient N = GetNutrient(Nutrients.N);

        data.waste += N.Extract(C.CurrentValue / 3);

        MediaNutrient AA = GetNutrient(Nutrients.AA);

        data.waste += AA.Extract(AA.CurrentValue / 2);
    }
Exemplo n.º 6
0
    void ImportNutrient(MediaNutrient nutrient, ref int energy)
    {
        if (energy == 0)
        {
            return;
        }
        int extracted = tile.nutrientState.Extract(nutrient.nutrient, Mathf.RoundToInt(energy * (1 + data.populationSize / 80f)));
        int surplus;

        nutrient.Deposit(extracted, out surplus);
        tile.nutrientState.Deposit(nutrient.nutrient, surplus);
        Debug.Log(string.Format(
                      "Import of {0} using {1} energy, extracted {2} which when deposited caused {3} surplus",
                      nutrient, energy, extracted, surplus));
    }
Exemplo n.º 7
0
    public void CauseDiffusion(NutrientState[] others)
    {
        int nNutrients = nutrients.Count;
        int nOthers    = others.Length;

        for (int i = 0; i < nNutrients; i++)
        {
            int own         = nutrients[i].Extract(diffusionFactor);
            int ownPerOther = own / 6;
            for (int j = 0; j < nOthers; j++)
            {
                MediaNutrient otherNutrient = others[j].GetNutrient(nutrients[i].nutrient);
                int           surplus       = 0;
                nutrients[i].Deposit(otherNutrient.Extract(diffusionFactor / 6), out surplus);
                otherNutrient.Deposit(ownPerOther + surplus, out surplus);
            }
        }
    }
Exemplo n.º 8
0
    void CreateEnergy()
    {
        MediaNutrient C       = GetNutrient(Nutrients.C, true);
        MediaNutrient N       = GetNutrient(Nutrients.N, true);
        MediaNutrient AA      = GetNutrient(Nutrients.AA, true);
        int           cFactor = 5;
        int           nFactor = 2;
        int           aFactor = 1;

        int production = Mathf.Min(
            C.CurrentValue / cFactor,
            N.CurrentValue / nFactor,
            AA.CurrentValue / aFactor);

        C.Extract(production * cFactor);
        N.Extract(production * nFactor);
        AA.Extract(production * aFactor);

        data.energy += production * 10;
    }
Exemplo n.º 9
0
    protected MediaNutrient GetNutrient(Nutrients nutrient, bool addIfMissing = false)
    {
        for (int i = 0, l = nutrients.Count; i < l; i++)
        {
            if (nutrients[i].nutrient == nutrient)
            {
                return(nutrients[i]);
            }
        }

        if (addIfMissing)
        {
            MediaNutrient mediaNutrient = new MediaNutrient();
            mediaNutrient.nutrient = nutrient;
            mediaNutrient.name     = NutrientToName(nutrient);
            nutrients.Add(mediaNutrient);
            return(mediaNutrient);
        }

        return(null);
    }