Skip to content

Commit e6f7804

Browse files
committed
Now serialization order is preserved. Fixed/improved serf state serialization.
1 parent a6789d2 commit e6f7804

20 files changed

+1806
-1392
lines changed

Freeserf.Core/Building.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public enum Type : byte
8282
// Max number of different types of resources accepted by buildings.
8383
public const uint MaxStock = 2;
8484

85-
[DataClass]
8685
internal class Stock : State, IComparable
8786
{
8887
Resource.Type type;
@@ -91,6 +90,7 @@ internal class Stock : State, IComparable
9190
byte requested;
9291
byte maximum;
9392

93+
[Data]
9494
public Resource.Type Type
9595
{
9696
get => type;
@@ -103,6 +103,7 @@ public Resource.Type Type
103103
}
104104
}
105105
}
106+
[Data]
106107
public byte Priority
107108
{
108109
get => priority;
@@ -115,6 +116,7 @@ public byte Priority
115116
}
116117
}
117118
}
119+
[Data]
118120
public byte Available
119121
{
120122
get => available;
@@ -127,6 +129,7 @@ public byte Available
127129
}
128130
}
129131
}
132+
[Data]
130133
public byte Requested
131134
{
132135
get => requested;
@@ -139,6 +142,7 @@ public byte Requested
139142
}
140143
}
141144
}
145+
[Data]
142146
public byte Maximum
143147
{
144148
get => maximum;

Freeserf.Core/BuildingState.cs

+28-12
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public enum BuildingStateFlags : byte
4646
FreeShieldPossible = 0x80,
4747
}
4848

49-
[DataClass]
5049
internal class BuildingState : State
5150
{
5251
private Building.Type type = Building.Type.None;
@@ -76,6 +75,7 @@ public override void ResetDirtyFlag()
7675
/// <summary>
7776
/// Type of this building
7877
/// </summary>
78+
[Data]
7979
public Building.Type Type
8080
{
8181
get => type;
@@ -88,9 +88,11 @@ public Building.Type Type
8888
}
8989
}
9090
}
91+
9192
/// <summary>
9293
/// Position of this building
9394
/// </summary>
95+
[Data]
9496
public MapPos Position
9597
{
9698
get => position;
@@ -103,9 +105,11 @@ public MapPos Position
103105
}
104106
}
105107
}
108+
106109
/// <summary>
107110
/// Index of flag connected to this building
108111
/// </summary>
112+
[Data]
109113
public word Flag
110114
{
111115
get => flag;
@@ -118,9 +122,11 @@ public word Flag
118122
}
119123
}
120124
}
125+
121126
/// <summary>
122127
/// Owner of this building
123128
/// </summary>
129+
[Data]
124130
public byte Player
125131
{
126132
get => player;
@@ -133,6 +139,8 @@ public byte Player
133139
}
134140
}
135141
}
142+
143+
[Data]
136144
public BuildingStateFlags Flags
137145
{
138146
get => flags;
@@ -145,9 +153,11 @@ public BuildingStateFlags Flags
145153
}
146154
}
147155
}
156+
148157
/// <summary>
149158
/// Threat level of military building
150159
/// </summary>
160+
[Data]
151161
public byte ThreatLevel
152162
{
153163
get => threatLevel;
@@ -160,9 +170,11 @@ public byte ThreatLevel
160170
}
161171
}
162172
}
173+
163174
/// <summary>
164175
/// Construction progress
165176
/// </summary>
177+
[Data]
166178
public word Progress
167179
{
168180
get => progress;
@@ -175,9 +187,11 @@ public word Progress
175187
}
176188
}
177189
}
190+
178191
/// <summary>
179192
/// Index of first knight in military building
180193
/// </summary>
194+
[Data]
181195
public word FirstKnight
182196
{
183197
get => firstKnight;
@@ -190,12 +204,14 @@ public word FirstKnight
190204
}
191205
}
192206
}
207+
193208
/// <summary>
194209
/// Can be one of 3 things:
195210
/// - Inventory index (for stocks and castle)
196211
/// - Tick (for burning buildings)
197212
/// - Level (for new large buildings that need terrain leveling)
198213
/// </summary>
214+
[Data]
199215
public word InventoryOrTickOrLevel
200216
{
201217
get => inventoryOrTickOrLevel;
@@ -208,9 +224,11 @@ public word InventoryOrTickOrLevel
208224
}
209225
}
210226
}
227+
211228
/// <summary>
212229
/// Stocks of this building
213230
/// </summary>
231+
[Data]
214232
public DirtyArray<Building.Stock> Stock { get; } = new DirtyArray<Building.Stock> // TODO: stock changes have to make the array dirty
215233
(
216234
new Building.Stock(), new Building.Stock()
@@ -219,32 +237,30 @@ public word InventoryOrTickOrLevel
219237
/// <summary>
220238
/// Inventory
221239
/// </summary>
222-
[Ignore]
223240
public word Inventory
224241
{
225242
get => InventoryOrTickOrLevel;
226243
set => InventoryOrTickOrLevel = value;
227244
}
245+
228246
/// <summary>
229247
/// Tick
230248
/// </summary>
231-
[Ignore]
232249
public word Tick
233250
{
234251
get => InventoryOrTickOrLevel;
235252
set => InventoryOrTickOrLevel = value;
236253
}
254+
237255
/// <summary>
238256
/// Level
239257
/// </summary>
240-
[Ignore]
241258
public word Level
242259
{
243260
get => InventoryOrTickOrLevel;
244261
set => InventoryOrTickOrLevel = value;
245262
}
246263

247-
[Ignore]
248264
public bool Constructing
249265
{
250266
get => Flags.HasFlag(BuildingStateFlags.Constructing);
@@ -256,7 +272,7 @@ public bool Constructing
256272
Flags &= ~BuildingStateFlags.Constructing;
257273
}
258274
}
259-
[Ignore]
275+
260276
public bool PlayingSfx // Note: This is used for weapon smiths as a flag for free shields. :(
261277
{
262278
get => Flags.HasFlag(BuildingStateFlags.PlayingSfx);
@@ -268,7 +284,7 @@ public bool Constructing
268284
Flags &= ~BuildingStateFlags.PlayingSfx;
269285
}
270286
}
271-
[Ignore]
287+
272288
public bool Active
273289
{
274290
get => Flags.HasFlag(BuildingStateFlags.Active);
@@ -280,7 +296,7 @@ public bool Active
280296
Flags &= ~BuildingStateFlags.Active;
281297
}
282298
}
283-
[Ignore]
299+
284300
public bool Burning
285301
{
286302
get => Flags.HasFlag(BuildingStateFlags.Burning);
@@ -292,7 +308,7 @@ public bool Burning
292308
Flags &= ~BuildingStateFlags.Burning;
293309
}
294310
}
295-
[Ignore]
311+
296312
public bool Holder
297313
{
298314
get => Flags.HasFlag(BuildingStateFlags.Holder);
@@ -304,7 +320,7 @@ public bool Holder
304320
Flags &= ~BuildingStateFlags.Holder;
305321
}
306322
}
307-
[Ignore]
323+
308324
public bool SerfRequested
309325
{
310326
get => Flags.HasFlag(BuildingStateFlags.SerfRequested);
@@ -316,7 +332,7 @@ public bool SerfRequested
316332
Flags &= ~BuildingStateFlags.SerfRequested;
317333
}
318334
}
319-
[Ignore]
335+
320336
public bool SerfRequestFailed
321337
{
322338
get => Flags.HasFlag(BuildingStateFlags.SerfRequestFailed);
@@ -328,7 +344,7 @@ public bool SerfRequestFailed
328344
Flags &= ~BuildingStateFlags.SerfRequestFailed;
329345
}
330346
}
331-
[Ignore]
347+
332348
public bool FreeShieldPossible
333349
{
334350
get => Flags.HasFlag(BuildingStateFlags.FreeShieldPossible);

Freeserf.Core/FlagState.cs

+19-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ public static TransporterFlags ToTransporterFlag(this Direction direction)
174174
}
175175
}
176176

177-
[DataClass]
178177
internal class FlagState : State
179178
{
180179
private MapPos position = Global.INVALID_MAPPOS;
@@ -209,6 +208,7 @@ public override void ResetDirtyFlag()
209208
}
210209
}
211210

211+
[Data]
212212
public MapPos Position
213213
{
214214
get => position;
@@ -221,6 +221,8 @@ public MapPos Position
221221
}
222222
}
223223
}
224+
225+
[Data]
224226
public Direction SearchDirection
225227
{
226228
get => searchDirection;
@@ -233,6 +235,8 @@ public Direction SearchDirection
233235
}
234236
}
235237
}
238+
239+
[Data]
236240
public word SearchNumber
237241
{
238242
get => searchNumber;
@@ -245,6 +249,8 @@ public word SearchNumber
245249
}
246250
}
247251
}
252+
253+
[Data]
248254
public byte PathConnections
249255
{
250256
get => pathConnections;
@@ -257,6 +263,8 @@ public byte PathConnections
257263
}
258264
}
259265
}
266+
267+
[Data]
260268
public EndPointFlags EndPointFlags
261269
{
262270
get => endPointFlags;
@@ -269,6 +277,8 @@ public EndPointFlags EndPointFlags
269277
}
270278
}
271279
}
280+
281+
[Data]
272282
public TransporterFlags TransporterFlags
273283
{
274284
get => transporterFlags;
@@ -281,6 +291,8 @@ public TransporterFlags TransporterFlags
281291
}
282292
}
283293
}
294+
295+
[Data]
284296
public FlagBuildingFlags FlagBuildingFlags
285297
{
286298
get => flagBuildingFlags;
@@ -293,18 +305,22 @@ public FlagBuildingFlags FlagBuildingFlags
293305
}
294306
}
295307
}
308+
309+
[Data]
296310
public DirtyArray<byte> FlagPaths { get; } = new DirtyArray<byte>(6);
311+
[Data]
297312
public DirtyArray<word> OtherEndpoints { get; } = new DirtyArray<word>(6);
313+
[Data]
298314
public DirtyArray<byte> OtherEndpointPaths { get; } = new DirtyArray<byte>(6);
315+
[Data]
299316
public DirtyArray<ResourceSlot> Slots { get; } = new DirtyArray<ResourceSlot>(Global.FLAG_MAX_RES_COUNT); // TODO: stock changes have to make the array dirty
300317

301-
[Ignore]
302318
public PathConnectionFlags PathConnectionFlags
303319
{
304320
get => (PathConnectionFlags)(PathConnections & 0x3f);
305321
set => PathConnections = (byte)((PathConnections & 0xC0) | ((byte)value & 0x3f));
306322
}
307-
[Ignore]
323+
308324
public byte OwnerIndex
309325
{
310326
get => (byte)((PathConnections >> 6) & 0x03);

0 commit comments

Comments
 (0)