Ejemplo n.º 1
0
 /// <summary>
 /// Add to Resource method.
 /// This style is used when a pool needs to be added to the current pool
 /// </summary>
 /// <param name="pool">HumanFoodStorePool to add to this pool</param>
 public void Add(HumanFoodStorePool pool)
 {
     if (pool.Amount > 0)
     {
         amount += pool.Amount;
     }
 }
Ejemplo n.º 2
0
 private void OnCLEMInitialiseResource(object sender, EventArgs e)
 {
     if (StartingAmount > 0)
     {
         HumanFoodStorePool initialpPool = new HumanFoodStorePool(StartingAmount, StartingAge);
         Add(initialpPool, this, "", "Starting value");
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Add to food store
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            HumanFoodStorePool pool;

            switch (resourceAmount.GetType().Name)
            {
            case "HumanFoodStorePool":
                pool = resourceAmount as HumanFoodStorePool;
                break;

            case "Double":
                pool = new HumanFoodStorePool((double)resourceAmount, 0);
                break;

            default:
                // expecting a HumanFoodStorePool or Double
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            if (pool.Amount > 0)
            {
                HumanFoodStorePool poolOfAge = Pools.Where(a => a.Age == pool.Age).FirstOrDefault();
                if (poolOfAge is null)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    poolOfAge.Add(pool.Amount);
                }

                ResourceTransaction details = new ResourceTransaction
                {
                    TransactionType   = TransactionType.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    RelatesToResource = relatesToResource,
                    Category          = category,
                    ResourceType      = this
                };
                base.LastGain   = pool.Amount;
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add to food store
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            HumanFoodStorePool pool;

            switch (resourceAmount)
            {
            case HumanFoodStorePool _:
                pool = resourceAmount as HumanFoodStorePool;
                break;

            case double _:
                pool = new HumanFoodStorePool((double)resourceAmount, 0);
                break;

            default:
                throw new Exception($"ResourceAmount object of type [{resourceAmount.GetType().Name}] is not supported in [r={Name}]");
            }

            if (pool.Amount > 0)
            {
                HumanFoodStorePool poolOfAge = Pools.Where(a => a.Age == pool.Age).FirstOrDefault();
                if (poolOfAge is null)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    poolOfAge.Add(pool.Amount);
                }

                ResourceTransaction details = new ResourceTransaction
                {
                    TransactionType   = TransactionType.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    RelatesToResource = relatesToResource,
                    Category          = category,
                    ResourceType      = this
                };
                base.LastGain   = pool.Amount;
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }