Unit.cs (3024B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // The Command & Conquer Map Editor and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // The Command & Conquer Map Editor and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 using MobiusEditor.Interface; 16 using System; 17 using System.Collections.Generic; 18 using System.ComponentModel; 19 using System.Drawing; 20 using System.Runtime.CompilerServices; 21 22 namespace MobiusEditor.Model 23 { 24 public class Unit : ICellOverlapper, ICellOccupier, INotifyPropertyChanged, ICloneable 25 { 26 public event PropertyChangedEventHandler PropertyChanged; 27 28 private UnitType type; 29 public UnitType Type { get => type; set => SetField(ref type, value); } 30 31 public Rectangle OverlapBounds => Type.OverlapBounds; 32 33 public bool[,] OccupyMask => Type.OccupyMask; 34 35 private HouseType house; 36 public HouseType House { get => house; set => SetField(ref house, value); } 37 38 private int strength; 39 public int Strength { get => strength; set => SetField(ref strength, value); } 40 41 private DirectionType direction; 42 public DirectionType Direction { get => direction; set => SetField(ref direction, value); } 43 44 private string mission; 45 public string Mission { get => mission; set => SetField(ref mission, value); } 46 47 private string trigger = Model.Trigger.None; 48 public string Trigger { get => trigger; set => SetField(ref trigger, value); } 49 50 public Color Tint { get; set; } = Color.White; 51 52 public Unit Clone() 53 { 54 return new Unit() 55 { 56 Type = Type, 57 House = House, 58 Strength = Strength, 59 Direction = Direction, 60 Mission = Mission, 61 Trigger = Trigger 62 }; 63 } 64 65 protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null) 66 { 67 if (EqualityComparer<T>.Default.Equals(field, value)) 68 { 69 return false; 70 } 71 field = value; 72 OnPropertyChanged(propertyName); 73 return true; 74 } 75 76 protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 77 78 object ICloneable.Clone() 79 { 80 return Clone(); 81 } 82 } 83 }