OSDN Git Service

W.I.P. IV: More reliable entity / block scanning (full depth chunk scan), rock stats...
[automap/automap.git] / Automap / Data / ColumnMeta.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Linq;
5
6 using Vintagestory.API.MathTools;
7 using Vintagestory.API.Common;
8
9 using ProtoBuf;
10
11
12 namespace Automap
13 {
14         [ProtoContract]
15         public struct ColumnMeta
16         {
17                 [ProtoMember(1)]
18                 public Vec2i Location;
19
20                 [ProtoMember(2)]
21                 public TimeSpan ChunkAge;//OLDEST CHUNK. from chunk last edit
22
23                 [ProtoMember(3)]
24                 public float Temperature;// Temperature - surface
25
26                 [ProtoMember(4)]
27                 public ushort YMax;// Y feature height
28
29                 [ProtoMember(5)]
30                 public Dictionary<int,uint> RockRatio;//[Column] Geographic region (rock) Ratio. [BlockID * count]
31
32                 [ProtoMember(6)]
33                 public float Fertility;
34
35                 [ProtoMember(7)]
36                 public float ForestDensity;
37
38                 [ProtoMember(8)]
39                 public float Rainfall;
40
41                 [ProtoMember(9)]
42                 public float ShrubDensity;
43
44                 [ProtoMember(10)]
45                 public ushort AirBlocks;
46
47                 [ProtoMember(11)]
48                 public ushort NonAirBlocks;
49
50                 //[ProtoMember(12,OverwriteList = true)]
51                 [ProtoIgnore]
52                 public ushort[ , ] HeightMap;
53
54                 public ColumnMeta(Vec2i loc, int chunkSize = 32)
55                 {
56                 Location = loc;
57                 ChunkAge = TimeSpan.Zero;
58                 Temperature = 0f;
59                 YMax = 0;
60                 RockRatio = new Dictionary<int, uint>( 10 );
61                 Fertility = 0f;
62                 ForestDensity = 0f;
63                 Rainfall = 0f;
64                 ShrubDensity = 0f;
65                 AirBlocks = 0;
66                 NonAirBlocks = 0;
67                 HeightMap = new ushort[chunkSize, chunkSize];
68                 }
69
70                 internal void UpdateFieldsFrom(ClimateCondition climate, IMapChunk mapChunk ,TimeSpan chunkAge)
71                 {
72                 this.ChunkAge = chunkAge;
73                 this.Temperature = climate.Temperature;
74                 this.Fertility = climate.Fertility;
75                 this.ForestDensity = climate.ForestDensity;
76                 this.Rainfall = climate.Rainfall;
77                 this.ShrubDensity = climate.ShrubDensity;
78
79                 this.YMax = mapChunk.YMax;
80                                         
81                 }
82         }
83
84         public class ColumnsMetadata : KeyedCollection<Vec2i, ColumnMeta>
85         {
86                 private ColumnsMetadata( )
87                 {
88                         throw new NotSupportedException();
89                 }
90
91                 public ColumnsMetadata(Vec2i startChunkColumn)
92                 {
93                 North_mostChunk = startChunkColumn.Y;
94                 South_mostChunk = startChunkColumn.Y;
95                 East_mostChunk = startChunkColumn.X;
96                 West_mostChunk = startChunkColumn.X;
97                 }
98
99                 public int North_mostChunk {
100                         get; private set;
101                 }
102
103                 public int South_mostChunk {
104                         get; private set;
105                 }
106
107                 public int East_mostChunk {
108                         get; private set;
109                 }
110
111                 public int West_mostChunk {
112                         get; private set;
113                 }
114
115                 protected override Vec2i GetKeyForItem(ColumnMeta item)
116                 {
117                 return item.Location;
118                 }
119
120                 internal void Update(ColumnMeta metaData)
121                 {
122                 if (this.Contains(metaData.Location)) {
123                 this.Remove(metaData.Location);
124                 this.Add(metaData);
125                 }
126                 else {
127                 this.Add(metaData);
128                 }
129
130                 }
131
132                 public new void Add(ColumnMeta newItem)
133                 {
134                 if (North_mostChunk > newItem.Location.Y) {
135                 North_mostChunk = newItem.Location.Y;
136                 }
137
138                 if (South_mostChunk < newItem.Location.Y) {
139                 South_mostChunk = newItem.Location.Y;
140                 }
141
142                 if (East_mostChunk < newItem.Location.X) {
143                 East_mostChunk = newItem.Location.X;
144                 }
145
146                 if (West_mostChunk > newItem.Location.X) {
147                 West_mostChunk = newItem.Location.X;
148                 }
149
150                 base.Add(newItem);
151                 }
152
153         }
154 }
155