示例#1
0
    public virtual float GiveTo(UrbAgent Target, UrbSubstanceTag Substance)
    {
        if (!Target.HasBody)
        {
            return(0);
        }

        float Amount = 0;

        UrbAction HoldAction = mAgent.PickAction(UrbTestCategory.Hold);

        if (HoldAction != null)
        {
            Amount = HoldAction.Execute(mAgent, Target);
            if (Target.IsGrasper)
            {
                Target.Grasper.TakeFrom(mAgent, Substance);
            }
            else if (Target.IsEater)
            {
                Amount = HeldComposition.TransferTo(Target.Eater.Stomach, Substance, Amount);
            }
            else
            {
                Amount = HeldComposition.TransferTo(Target.mBody.BodyComposition, Substance, Amount);
            }
        }

        return(Amount);
    }
示例#2
0
    // Intended to be called when the agent is deceased-- A "magical"
    //means of mass disappearing into the void, and therefore, a bit
    //of a compromise to the system's integrity.
    // Deceased bodies will get removed from the map over time.
    //In the future, this should be replaced with actual decay mechanisms
    //FOR EXAMPLE: Fur/teeth are not eaten by sneks.
    // Could solve that loophole by having fur first in the ordering?
    public void DecaySubstances(int decay = 2)
    {
        Assert.IsTrue(decay > 0, "decay must be > 0");

        ContainingComposition?.DecaySubstances();

        UrbSubstanceTag[] subs   = Substances.Keys.ToArray();
        float[]           values = Substances.Values.ToArray();
        float             val;

        for (int i = 0; i < subs.Length; i++)
        {
            val = values[i];
            if (val <= 0)
            {
                continue;
            }

            UrbSubstanceTag tag = subs[i];

            if (val <= 1)
            {
                UsedCapacity    -= val;
                Substances[tag] -= val;
                break;
            }

            float reduction = val / decay;
            Substances[tag] -= reduction;
            UsedCapacity    -= reduction;
            //I was going to have the
            break;
        }
    }
 public static bool Remove(UrbSubstanceTag Tag)
 {
     if (Properties == null || !Properties.ContainsKey(Tag))
     {
         return(false);
     }
     return(Properties.Remove(Tag));
 }
 public static bool CheckScent(UrbSubstanceTag Substance, UrbScentTag Scent)
 {
     if (SubstanceByScent.ContainsKey(Scent))
     {
         return(SubstanceByScent[Scent].Contains(Substance));
     }
     return(false);
 }
示例#5
0
    public float Impact(UrbComposition ImpactSource, UrbSubstanceTag ImpactSubstance, float Force)
    {
        float Result = ImpactSource[ImpactSubstance];

        Result = PenetrationCheck(ImpactSubstance, Result, Force);

        return(Result);
    }
    public static UrbSubstanceProperty Get(UrbSubstanceTag Tag)
    {
        if (Properties == null || !Properties.ContainsKey(Tag))
        {
            return(Default);
        }

        return(Properties[Tag]);
    }
    protected static bool UnregisterScent(UrbSubstanceTag Substance, UrbScentTag Scent)
    {
        if (SubstanceByScent.ContainsKey(Scent))
        {
            if (SubstanceByScent[Scent].Contains(Substance))
            {
                return(SubstanceByScent[Scent].Remove(Substance));
            }
        }

        return(false);
    }
示例#8
0
 public override bool SetComponentData(UrbComponentData Data)
 {
     EnergyDebt = UrbEncoder.GetField("EnergyDebt", Data);
     BodyEnergyReserveStorage = UrbEncoder.GetEnum <UrbSubstanceTag>("BodyEnergyReserveStorage", Data);
     BodyGrowthRecipe         = UrbEncoder.GetSubstancesFromArray("BodyGrowthRecipe", Data);
     InitializeGrowthRecipes();
     if (IsEater)
     {
         InitializeReserveRecipes();
     }
     return(true);
 }
示例#9
0
    public float RemoveSubstance(UrbSubstanceTag Tag, float Amount)
    {
        if (Amount <= 0.0f)
        {
            return(0.0f);
        }

        if (ContainingComposition != null)
        {
            MaxCapacity = ContainingComposition.AvailableCapacity + UsedCapacity;
        }

        float TransferAmount = Amount;
        //Debug.Log("Attempting Transfer " + TransferAmount + " from " + Tag.ToString());

        //Is this Supposed to be addition?
        float CapacityAfter = UsedCapacity + Amount;

        if (CapacityAfter < 0)
        {
            TransferAmount += CapacityAfter;
        }
        //Debug.Log("After Capacity Check Transfer " + TransferAmount);

        if (Substances.ContainsKey(Tag))
        {
            if (Substances[Tag] >= TransferAmount)
            {
                Substances[Tag] -= TransferAmount;
            }
            else
            {
                TransferAmount += Substances[Tag] - TransferAmount;
                Substances[Tag] = 0;
                Dirty           = true;
            }
            // Debug.Log("After Quantity Check " + TransferAmount);
        }
        else
        {
            TransferAmount = 0;
        }
        UsedCapacity -= TransferAmount;
        if (ContainingComposition != null)
        {
            ContainingComposition.UsedCapacity -= TransferAmount;
        }

        Assert.IsFalse(float.IsInfinity(TransferAmount) || float.IsNaN(TransferAmount));

        return(TransferAmount);
    }
示例#10
0
    public float GetProportionOf(UrbSubstanceTag Tag)
    {
        if (Tag == UrbSubstanceTag.None || UsedCapacity <= 0)
        {
            return(0.0f);
        }
        else if (Tag == UrbSubstanceTag.All)
        {
            return(1.0f);
        }

        return(this[Tag] / UsedCapacity);
    }
示例#11
0
    public float this[UrbSubstanceTag Tag] {
        get {
            if (Tag == UrbSubstanceTag.All)
            {
                return(UsedCapacity);
            }

            if (Substances.TryGetValue(Tag, out float val))
            {
                return(val);
            }

            return(0.0f);
        }
    }
    protected static bool RegisterScent(UrbSubstanceTag Substance, UrbScentTag Scent)
    {
        if (!SubstanceByScent.ContainsKey(Scent))
        {
            SubstanceByScent.Add(Scent, new List <UrbSubstanceTag>());
        }

        if (SubstanceByScent[Scent].Contains(Substance))
        {
            return(false);
        }

        SubstanceByScent[Scent].Add(Substance);

        return(true);
    }
    public static void Set(UrbSubstanceTag Tag, UrbSubstanceProperty Property)
    {
        if (Properties == null)
        {
            Properties = new Dictionary <UrbSubstanceTag, UrbSubstanceProperty>();
        }

        if (Properties.ContainsKey(Tag))
        {
            if (Property.Hardness > -1)
            {
                Properties[Tag].Hardness = Property.Hardness;
            }
            if (Property.Flexibility > -1)
            {
                Properties[Tag].Flexibility = Property.Flexibility;
            }
            if (Property.Maleability > -1)
            {
                Properties[Tag].Flexibility = Property.Maleability;
            }
            if (Property.PersonalScent.Length > 0)
            {
                for (int i = 0; i < Properties[Tag].Scent.Length; i++)
                {
                    UnregisterScent(Tag, Properties[Tag].Scent[i]);
                }
                Properties[Tag].Scent = Property.PersonalScent;
            }
            if (Property.Components.Length > 0)
            {
                Properties[Tag].Components = Property.Components;
            }
        }
        else
        {
            Properties.Add(Tag, Property);
        }

        for (int i = 0; i < Properties[Tag].Scent.Length; i++)
        {
            RegisterScent(Tag, Properties[Tag].Scent[i]);
        }

        return;
    }
示例#14
0
    public float this[UrbSubstanceTag Tag] {
        get {
            if (Occupants.Count <= 0)
            {
                return(0);
            }

            float Amount = 0;

            for (int i = 0; i < Occupants.Count; i++)
            {
                if (Occupants[i].HasBody)
                {
                    Amount += Occupants[i].mBody.BodyComposition[Tag];
                }
            }
            return(Amount);
        }
    }
示例#15
0
    public float AddSubstance(UrbSubstanceTag Tag, float Amount)
    {
        if (ContainingComposition != null)
        {
            MaxCapacity = ContainingComposition.AvailableCapacity + UsedCapacity;
        }

        if (Amount <= 0.0f)
        {
            return(0.0f);
        }

        float TransferAmount = Amount;

        float CapacityAfter = UsedCapacity + Amount;

        if (CapacityAfter > MaxCapacity)
        {
            TransferAmount -= CapacityAfter - MaxCapacity;
        }

        if (Substances.ContainsKey(Tag))
        {
            Substances[Tag] += TransferAmount;
        }
        else
        {
            Substances.Add(Tag, TransferAmount);
            Dirty = true;
        }

        UsedCapacity += TransferAmount;

        if (ContainingComposition != null)
        {
            ContainingComposition.UsedCapacity += TransferAmount;
        }

        Assert.IsFalse(float.IsInfinity(TransferAmount) || float.IsNaN(TransferAmount));

        return(TransferAmount);
    }
示例#16
0
    public float PenetrationCheck(UrbSubstanceTag Penetrator, float Amount, float Force)
    {
        if (Layers == null || Layers.Length == 0)
        {
            return(Amount);
        }

        float Result      = 0;
        float Depth       = Force;
        float PenHardness = UrbSubstanceProperties.Get(Penetrator).Hardness;

        for (int i = 0; i < Layers.Length; i++)
        {
            float LayerThickness   = Thickness(Layers[i]);
            float LayerHardness    = UrbSubstanceProperties.Get(Layers[i]).Hardness;
            float LayerFlexibility = UrbSubstanceProperties.Get(Layers[i]).Flexibility;

            Depth *= PenHardness / LayerHardness;


            if (Depth > LayerThickness)
            {
                float Damage = LayerFlexibility > 0 ? (Amount * LayerThickness) / LayerFlexibility : Amount * LayerThickness;
                LayerDamage[i] += Damage;
                Result         += Damage;
                Depth          -= LayerThickness;
            }
            else
            {
                float Damage = LayerFlexibility > 0 ? (Amount * Depth) / LayerFlexibility : Amount * Depth;
                LayerDamage[i] += Damage;
                Result         += Damage;
                break;
            }
        }

        return(Result);
    }
示例#17
0
    public float EmptyInto(UrbComposition Target)
    {
        float Result = 0;

        UrbSubstanceTag[] tags = new UrbSubstanceTag[Substances.Keys.Count];
        int i = 0;

        foreach (UrbSubstanceTag tag in Substances.Keys)
        {
            tags[i] = tag;
            i++;
        }

        for (int t = 0; t < tags.Length; t++)
        {
            float Amount = Substances[tags[t]];
            Result += TransferTo(Target, tags[t], Amount);
        }

        Assert.IsFalse(float.IsInfinity(Result) || float.IsNaN(Result));

        return(Result);
    }
示例#18
0
    public float TransferTo(UrbComposition Target, UrbSubstanceTag Tag, float Amount)
    {
        if (Amount <= 0.0f)
        {
            return(0.0f);
        }

        //float TransferAmount = Mathf.Min(Amount, Target.AvailableCapacity);

        float TransferAmount = RemoveSubstance(Tag, Amount);

        if (TransferAmount > 0)
        {
            Target.AddSubstance(Tag, TransferAmount);
        }
        else
        {
            //Debug.Log( Tag.ToString() + " Not Available to Transfer.");
        }

        Assert.IsFalse(float.IsInfinity(TransferAmount) || float.IsNaN(TransferAmount));

        return(TransferAmount);
    }
示例#19
0
 public static bool SubstanceSmellsLike(UrbSubstanceTag Substance, UrbScentTag Scent)
 {
     return(UrbSubstanceProperties.CheckScent(Substance, Scent));
 }
示例#20
0
 public static UrbScentTag[] Scent(UrbSubstanceTag input)
 {
     return(UrbSubstanceProperties.Get(input).Scent);
 }
示例#21
0
 public float Thickness(UrbSubstanceTag Tag)
 {
     return(ContainingComposition.GetProportionOf(Tag) * Radius);
 }