public static Trigger ReadFrom(PrimitiveReader reader) { Trigger trigger = new Trigger(); //System.Diagnostics.Debugger.Break(); trigger.Enabled = reader.ReadUInt32() != 0; trigger.Looping = reader.ReadUInt32() != 0; trigger.Unknown1 = reader.ReadUInt8(); trigger.DisplayAsObjective = reader.ReadUInt8() != 0; trigger.ObjectivesDescriptionOrder = reader.ReadUInt32(); trigger.Unknown2 = reader.ReadUInt32(); trigger.Description = Utils.ReadUInt32LengthPrefixedString(reader); trigger.Name = Utils.ReadUInt32LengthPrefixedString(reader); //System.Diagnostics.Debugger.Break(); int effectsCount = reader.ReadInt32(); if (effectsCount < 0) { effectsCount = 0; } TriggerEffect[] effects = new TriggerEffect[effectsCount]; for (int i = 0; i < effects.Length; i++) { effects[i] = TriggerEffect.ReadFrom(reader); } for (int i = 0; i < effects.Length; i++) { effects[i].DisplayOrder = reader.ReadInt32(); } trigger.Effects = effects; int conditionsCount = reader.ReadInt32(); if (conditionsCount < 0) { conditionsCount = 0; } TriggerCondition[] conditions = new TriggerCondition[conditionsCount]; for (int i = 0; i < conditions.Length; i++) { conditions[i] = TriggerCondition.ReadFrom(reader); } for (int i = 0; i < conditions.Length; i++) { conditions[i].DisplayOrder = reader.ReadInt32(); } trigger.Conditions = conditions; //System.Diagnostics.Debugger.Break(); return(trigger); }
public static TriggerEffect ReadFrom(PrimitiveReader reader) { TriggerEffect effect = new TriggerEffect(); effect.Type = reader.ReadInt32(); effect.Check = reader.ReadInt32(); if (effect.Check != 0x17) { throw new InvalidDataException("Expected 0x17 for check."); } effect.AiGoal = reader.ReadInt32(); effect.Amount = reader.ReadInt32(); effect.ResourceType = reader.ReadInt32(); effect.Diplomacy = reader.ReadInt32(); int selectedUnitsCount = reader.ReadInt32(); effect.UnitLocation = reader.ReadInt32(); effect.UnitType = reader.ReadInt32(); effect.PlayerSource = reader.ReadInt32(); effect.PlayerTarget = reader.ReadInt32(); effect.Technology = reader.ReadInt32(); effect.StringTableIndex = reader.ReadInt32(); effect.Unknown = reader.ReadInt32(); effect.DisplayTime = reader.ReadInt32(); effect.TriggerIndex = reader.ReadInt32(); effect.Location = new Point2I(reader.ReadInt32(), reader.ReadInt32()); effect.BottomLeft = new Point2I(reader.ReadInt32(), reader.ReadInt32()); effect.UpperRight = new Point2I(reader.ReadInt32(), reader.ReadInt32()); effect.UnitGroup = reader.ReadInt32(); effect.UnitGroupType = reader.ReadInt32(); effect.InstructionPanel = reader.ReadInt32(); effect.Text = Utils.ReadUInt32LengthPrefixedString(reader); effect.SoundFile = Utils.ReadUInt32LengthPrefixedString(reader); if (selectedUnitsCount < 0) { selectedUnitsCount = 0; } uint[] selectedUnits = new uint[selectedUnitsCount]; for (int i = 0; i < selectedUnits.Length; i++) { selectedUnits[i] = reader.ReadUInt32(); } effect.SelectedUnits = selectedUnits; return(effect); }