InfantryType.cs (3344B)
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 MobiusEditor.Render; 17 using MobiusEditor.Utility; 18 using System; 19 using System.Drawing; 20 21 namespace MobiusEditor.Model 22 { 23 public class InfantryType : ITechnoType, IBrowsableType 24 { 25 public sbyte ID { get; private set; } 26 27 public string Name { get; private set; } 28 29 public string DisplayName { get; private set; } 30 31 public string OwnerHouse { get; private set; } 32 33 public Size RenderSize { get; set; } 34 35 public Image Thumbnail { get; set; } 36 37 public InfantryType(sbyte id, string name, string textId, string ownerHouse) 38 { 39 ID = id; 40 Name = name; 41 DisplayName = Globals.TheGameTextManager[textId]; 42 OwnerHouse = ownerHouse; 43 } 44 45 public InfantryType(sbyte id, string name, string textId) 46 : this(id, name, textId, null) 47 { 48 } 49 50 public override bool Equals(object obj) 51 { 52 if (obj is InfantryType) 53 { 54 return this == obj; 55 } 56 else if (obj is sbyte) 57 { 58 return ID == (sbyte)obj; 59 } 60 else if (obj is string) 61 { 62 return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase); 63 } 64 65 return base.Equals(obj); 66 } 67 68 public override int GetHashCode() 69 { 70 return ID.GetHashCode(); 71 } 72 73 public override string ToString() 74 { 75 return Name; 76 } 77 78 public void Init(GameType gameType, TheaterType theater, HouseType house, DirectionType direction) 79 { 80 if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, Name, 4, out Tile tile)) 81 { 82 RenderSize = new Size(tile.Image.Width / Globals.TileScale, tile.Image.Height / Globals.TileScale); 83 } 84 85 var mockInfantry = new Infantry(null) 86 { 87 Type = this, 88 House = house, 89 Strength = 256, 90 Direction = direction 91 }; 92 var infantryThumbnail = new Bitmap(Globals.TileWidth, Globals.TileHeight); 93 using (var g = Graphics.FromImage(infantryThumbnail)) 94 { 95 MapRenderer.Render(theater, Point.Empty, Globals.TileSize, mockInfantry, InfantryStoppingType.Center).Item2(g); 96 } 97 Thumbnail = infantryThumbnail; 98 } 99 } 100 }