Rev 1112 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
1111 | werner | 2 | #ifndef SAPLINGS_H |
3 | #define SAPLINGS_H |
||
4 | |||
5 | #include "grid.h" |
||
6 | |||
7 | struct SaplingTree { |
||
8 | SaplingTree() { age=0; species_index=0; stress_years=0; flags=0; height=0.f; } |
||
9 | short unsigned int age; // number of consectuive years the sapling suffers from dire conditions |
||
10 | short unsigned int species_index; // index of the species within the resource-unit-species container |
||
11 | unsigned char stress_years; // (upper 16bits) + age of sapling (lower 16 bits) |
||
12 | unsigned char flags; |
||
13 | float height; // height of the sapling in meter |
||
14 | bool is_occupied() const { return height>0.f; } |
||
15 | void setSapling(const float h_m, const int age_yrs, const int species_idx) { height=h_m; age=static_cast<short unsigned int>(age_yrs); stress_years=0; species_index=species_idx; } |
||
16 | }; |
||
17 | #define NSAPCELLS 5 |
||
18 | struct SaplingCell { |
||
19 | enum ECellState { CellInvalid=0, CellFree=1, CellFull=2}; |
||
20 | SaplingCell() { |
||
21 | state=CellInvalid; |
||
22 | } |
||
23 | ECellState state; |
||
24 | SaplingTree saplings[NSAPCELLS]; |
||
25 | void checkState() { if (state==CellInvalid) return; |
||
26 | bool free=true; |
||
27 | for (int i=0;i<NSAPCELLS;++i) { |
||
28 | // locked for all species, if a sapling of one species >1.3m |
||
29 | if (saplings[i].height>1.3f) {free=false; break; } |
||
30 | // locked, if all slots are occupied. |
||
31 | if (!saplings[i].is_occupied()) |
||
32 | free=true; |
||
33 | } |
||
34 | state = free? CellFree : CellFull; |
||
35 | } |
||
36 | }; |
||
37 | class ResourceUnit; |
||
38 | |||
39 | |||
40 | class Saplings |
||
41 | { |
||
42 | public: |
||
43 | Saplings(); |
||
44 | void setup(); |
||
45 | // main functions |
||
46 | void establishment(const ResourceUnit *ru); |
||
47 | void clearStats() { mAdded=0; mTested=0;} |
||
48 | int saplingsAdded() const { return mAdded; } |
||
49 | int pixelTested() const { return mTested; } |
||
50 | |||
51 | private: |
||
52 | Grid<SaplingCell> mGrid; |
||
53 | int mAdded; |
||
54 | int mTested; |
||
55 | }; |
||
56 | |||
57 | #endif // SAPLINGS_H |