Developing resources
Advanced topic - requires coding skills
Resource components in CLEM are designed manage the movement of a resource in and out of the store thereby tracking the state and availability of the resource (see Resources). There are two categories of resource components, the Resource Group and the Resource Type. The Resource Group specifies the type of resource such as animal food, finance, water or labour. This group contains any number of components of the associated Resource Type as children.
The resource and resource type components are designed to be simple stores providing transaction management with limited associated code. The philosophy of CLEM is that Activities should contain all the code to work with resources. There are some exceptions to this rule where additional logic is required to manage the resource such as labour. CLEM aims to provide as much resource type agnostic code as possible to provide functionality across resources in future such as using any resource for a payment as opposed to only finances.

Each type of resource in your simulation must have a Resource Group. For example, there is a HumanFoodStore component to hold all human food stores present (e.g. wheat, milk, eggs and meat). This component handles the tracking of, access to the associated Resource Types and reporting of transactions to the output ledgers.
The Resource Group is a component that derives from the CLEM.Resources.ResourceBaseWithTransactions base class. This class provides a property to hold the Last Transaction details (type ResourceTransaction), a TransactionOccurred event and OnTransactionOccurred method to fire the event all for reporting. It also contains a method to return a Resource Type from its children by a specified name.
Each Resource Group may also have specific properties such as CurrencyName for the finance group.
Resource Groups all subscribe to the Commencing and Completed events where they add and remove bindings to the TransactionOccurred event of each child respectively.

The Resource Type represents a specific resource being stored. The Models.Core.ValidParent attribute should be set to the relevant Resource group to ensure that only this type is available when "add model" is selected from the parent group.
Each Resource Type may also have specific properties relating to the resource (e.g. interest rate for finance resource types) but must inherit the following structure.

Each resource type inherits the IResourceType interface. This ensures the resource follows the standard that CLEM uses to manage all resources and resource types are only updated through accepted methods. with store amounts a private property

void Add(object resourceAmount, CLEMModel activity, string reason);
The void Add() method must be provided for each resource type. This method includes three parameters. The resourceAmount is passed as an object. Each resource type can therefore receive resources as different types (e.g. double for finance, FoodPacket for AnimalFoodStore). The activity is the activity performing the transaction and reason is a description of the transaction for ledger reporting. The Add method must raise a TransactionOccurred event.

void Remove(ResourceRequest request);
The void Remove() method must be provided for each resource type. This method passes a ResourceRequest (see Using resources in activities). The Remove method must raise a TransactionOccurred event.

double Amount { get; }
The void Remove() method must be provided for each resource type. This method passes a ResourceRequest (see Using resources in activities).
Special case: The amount returned from the graze food store is the sum of the amount in each pasture pool in the resource.
Special case: The amount returned from the land type is the available land. This is needed as land provides the concept of allowing a resource to use all available land. This isn't taken from the land resource and is available other activities to take or even return land and add to the unused portion. Therefore the land type resource needs to track and manage the state of unused land.

ResourcePricing Price { get; }
This property stores the ResourcePricing component if supplied.

string Units { get; }
The nominal units that this resource is stored in. This allows resources to be treated in the expected units such as each for eggs, litres for milk and kg for wheat.

Each Resource Type will generally subscribe to the CLEMInitialiseResource event where initialisation can occur before a simulation. This can include assignment of the initial store ensuring the transaction is recorded.