-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBuildingObject.cs
More file actions
74 lines (67 loc) · 2.81 KB
/
BuildingObject.cs
File metadata and controls
74 lines (67 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Definitions.ObjectModels.Graphics;
using Definitions.ObjectModels.Objects.Common;
using Definitions.ObjectModels.Types;
using System.ComponentModel.DataAnnotations;
namespace Definitions.ObjectModels.Objects.Building;
public class BuildingObject : ILocoStruct, IHasBuildingComponents
{
public static class Constants
{
public const int MaxVariationsCount = 32;
public const int MaxHeightsCount = 64;
public const int MaxAnimationsCount = 64;
public const int MaxProducedCargoType = 2;
public const int MaxRequiredCargoType = 2;
public const int MaxElevatorHeightSequencesCount = 4;
}
public BuildingComponents BuildingComponents { get; set; } = new();
public uint32_t Colours { get; set; }
public uint16_t DesignedYear { get; set; }
public uint16_t ObsoleteYear { get; set; }
public BuildingObjectFlags Flags { get; set; }
public uint8_t CostIndex { get; set; }
public uint16_t SellCostFactor { get; set; }
public uint8_t ScaffoldingSegmentType { get; set; }
public Colour ScaffoldingColour { get; set; }
public uint8_t GeneratorFunction { get; set; } // for misc buildings generator function, otherwise its a set of flags representing town densities the building can be built in
public uint8_t AverageNumberOnMap { get; set; }
public List<uint8_t> ProducedQuantity { get; set; } = [];
public List<ObjectModelHeader> ProducedCargo { get; set; } = [];
public List<ObjectModelHeader> RequiredCargo { get; set; } = [];
public uint8_t var_A6 { get; set; }
public uint8_t var_A7 { get; set; }
public uint8_t var_A8 { get; set; }
public uint8_t var_A9 { get; set; }
public int16_t DemolishRatingReduction { get; set; }
public uint8_t var_AC { get; set; }
public List<uint8_t[]> ElevatorHeightSequences { get; set; } = [];
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
#pragma warning disable IL2026 // ValidationContext constructor uses reflection; this usage is safe as the target types are always present at runtime.
var bcValidationContext = new ValidationContext(BuildingComponents);
#pragma warning restore IL2026
foreach (var result in BuildingComponents.Validate(bcValidationContext))
{
yield return result;
}
if (ProducedQuantity.Count != 2)
{
yield return new ValidationResult($"{nameof(ProducedQuantity)} must have exactly 2 entries.", [nameof(ProducedQuantity)]);
}
if (Flags.HasFlag(BuildingObjectFlags.MiscBuilding))
{
if (GeneratorFunction >= 4)
{
yield return new ValidationResult($"Buildings with the {nameof(BuildingObjectFlags.MiscBuilding)} flag can only use generator functions < 4.", [nameof(GeneratorFunction)]);
}
}
if (var_AC != 0xFF)
{
// Max of 8 different building categories
if (var_AC >= 8)
{
yield return new ValidationResult($"{nameof(var_AC)} must either be 255 or < 8.", [nameof(var_AC)]);
}
}
}
}