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