Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1033 werner 1
/********************************************************************************************
2
**    iLand - an individual based forest landscape and disturbance model
3
**    http://iland.boku.ac.at
4
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
5
**
6
**    This program is free software: you can redistribute it and/or modify
7
**    it under the terms of the GNU General Public License as published by
8
**    the Free Software Foundation, either version 3 of the License, or
9
**    (at your option) any later version.
10
**
11
**    This program is distributed in the hope that it will be useful,
12
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
**    GNU General Public License for more details.
15
**
16
**    You should have received a copy of the GNU General Public License
17
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
********************************************************************************************/
811 werner 19
#ifndef AGENTTYPE_H
20
#define AGENTTYPE_H
873 werner 21
#include <QHash>
22
#include <QVector>
874 werner 23
#include <QJSValue>
904 werner 24
 
25
 
907 werner 26
namespace ABE {
870 werner 27
 
28
 
873 werner 29
class FMSTP; // forward
940 werner 30
class FMUnit; // forward
873 werner 31
class FMStand; // forward
938 werner 32
class Agent; // forward
873 werner 33
 
940 werner 34
class AgentUpdate
35
{
36
public:
944 werner 37
    AgentUpdate(): mWhat(UpdateInvalid), mAge(-1), mYear(-1), mCounter(0) {}
940 werner 38
    enum UpdateType { UpdateInvalid, UpdateThinning, UpdateU, UpdateSpecies };
942 werner 39
    static UpdateType label(const QString &name);
944 werner 40
    bool isValid() const { return mCounter>0; }
41
    void setCounter(int n) { mCounter = n; }
42
    void decrease() {--mCounter; }
43
    QString dump();
942 werner 44
    // getters
45
    UpdateType type() const { return mWhat; }
46
    const QString &value() const { return mValue;}
47
    const QString &afterActivity() const { return mAfterActivity; }
48
    int age() const {return mAge; }
49
    // setters
940 werner 50
    void setType(UpdateType type) { mWhat = type; }
51
    void setValue(QString new_value) { mValue = new_value; }
52
    void setTimeAge(int age) { mAge = age; }
53
    void setTimeYear(int year) { mYear = year; }
54
    void setTimeActivity(QString act) { mAfterActivity = act; }
55
private:
56
    UpdateType mWhat;
57
    QString mValue; ///< new value of the given type
58
    int mAge; ///< update should happen in that age
59
    int mYear; ///< update should happen in the given year
60
    QString mAfterActivity; ///< update should happen after given activity is executed
61
 
944 werner 62
    int mCounter; ///< number of stands that have not "seen" this update request
63
 
940 werner 64
    friend class AgentType;
65
};
66
 
942 werner 67
/** AgentType is the archtype agent including the
68
 *  agents decision logic. The 'Agent' class describes an indivdual agent.
69
 *
70
 **/
811 werner 71
class AgentType
72
{
73
public:
873 werner 74
 
811 werner 75
    AgentType();
876 werner 76
    const QString &name() const {return mName; }
873 werner 77
    /// setup the definition of STPs for the agent
876 werner 78
    void setupSTP(QJSValue agent_code, const QString agent_name);
1208 werner 79
    /// add a STP to the list of available STPs for the agent
80
    void addSTP(QString stp_name);
938 werner 81
    /// create an agent of the agent type
82
    Agent *createAgent(QString agent_name=QString());
942 werner 83
 
958 werner 84
    void addAgentUpdate(const AgentUpdate &update, FMUnit *unit);
942 werner 85
    bool agentUpdateForStand(FMStand *stand, QString after_activity, int age);
86
 
87
 
890 werner 88
    /// get stand treatment program by name; return 0 if the stp is not available.
89
    FMSTP *stpByName(const QString &name);
939 werner 90
    /// access to the javascript object
91
    QJSValue &jsObject() { return mJSObj; }
940 werner 92
 
93
    /// return the index (0-based) of the species composition given by 'key'. Returns -1 if not found.
94
    int speciesCompositionIndex(const QString &key);
95
    QString speciesCompositionName(const int index);
96
 
873 werner 97
private:
98
    QString mName; // agent name
876 werner 99
    QJSValue mJSObj; ///< javascript object
873 werner 100
    QHash<QString,FMSTP*> mSTP; ///< list of all STP linked to this agent type
940 werner 101
    QVector<QString> mSpeciesCompositions; ///< list of available target species composition (objects)
942 werner 102
    QMultiHash<const FMUnit*, AgentUpdate> mAgentChanges;
811 werner 103
};
104
 
870 werner 105
} // namespace
811 werner 106
#endif // AGENTTYPE_H