OSDN Git Service

indentation
[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                 {
101                         get; private set;
102                 }
103
104                 public int South_mostChunk
105                 {
106                         get; private set;
107                 }
108
109                 public int East_mostChunk
110                 {
111                         get; private set;
112                 }
113
114                 public int West_mostChunk
115                 {
116                         get; private set;
117                 }
118
119                 protected override Vec2i GetKeyForItem(ColumnMeta item)
120                 {
121                         return item.Location;
122                 }
123
124                 internal void Update(ColumnMeta metaData)
125                 {
126                         if (this.Contains(metaData.Location))
127                         {
128                                 this.Remove(metaData.Location);
129                                 this.Add(metaData);
130                         }
131                         else
132                         {
133                                 this.Add(metaData);
134                         }
135
136                 }
137
138                 public new void Add(ColumnMeta newItem)
139                 {
140                         if (North_mostChunk > newItem.Location.Y)
141                         {
142                                 North_mostChunk = newItem.Location.Y;
143                         }
144
145                         if (South_mostChunk < newItem.Location.Y)
146                         {
147                                 South_mostChunk = newItem.Location.Y;
148                         }
149
150                         if (East_mostChunk < newItem.Location.X)
151                         {
152                                 East_mostChunk = newItem.Location.X;
153                         }
154
155                         if (West_mostChunk > newItem.Location.X)
156                         {
157                                 West_mostChunk = newItem.Location.X;
158                         }
159
160                         base.Add(newItem);
161                 }
162
163         }
164 }
165