BuildingType.cs (6257B)
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 System; 18 using System.Drawing; 19 20 namespace MobiusEditor.Model 21 { 22 public class BuildingType : ICellOverlapper, ICellOccupier, ITechnoType, IBrowsableType 23 { 24 public sbyte ID { get; private set; } 25 26 public string Name { get; private set; } 27 28 public string DisplayName { get; private set; } 29 30 public string Tilename { get; private set; } 31 32 public Rectangle OverlapBounds => new Rectangle(Point.Empty, new Size(OccupyMask.GetLength(1), OccupyMask.GetLength(0))); 33 34 public bool[,] OccupyMask { get; private set; } 35 36 public bool[,] BaseOccupyMask { get; private set; } 37 38 public Size Size { get; private set; } 39 40 public bool HasBib { get; private set; } 41 42 public string OwnerHouse { get; private set; } 43 44 public TheaterType[] Theaters { get; private set; } 45 46 public bool IsFake { get; private set; } 47 48 public bool HasTurret { get; private set; } 49 50 public string FactoryOverlay { get; private set; } 51 52 public Image Thumbnail { get; set; } 53 54 public BuildingType(sbyte id, string name, string textId, bool[,] occupyMask, bool hasBib, string ownerHouse, TheaterType[] theaters, bool isFake, bool hasTurret, string factoryOverlay) 55 { 56 ID = id; 57 Name = isFake ? (name.Substring(0, name.Length - 1) + "f") : name; 58 DisplayName = Globals.TheGameTextManager[textId]; 59 Tilename = name; 60 BaseOccupyMask = occupyMask; 61 Size = new Size(BaseOccupyMask.GetLength(1), BaseOccupyMask.GetLength(0)); 62 HasBib = hasBib; 63 OwnerHouse = ownerHouse; 64 Theaters = theaters; 65 IsFake = isFake; 66 HasTurret = hasTurret; 67 FactoryOverlay = factoryOverlay; 68 69 if (HasBib) 70 { 71 OccupyMask = new bool[BaseOccupyMask.GetLength(0) + 1, BaseOccupyMask.GetLength(1)]; 72 for (var i = 0; i < BaseOccupyMask.GetLength(0) - 1; ++i) 73 { 74 for (var j = 0; j < BaseOccupyMask.GetLength(1); ++j) 75 { 76 OccupyMask[i, j] = BaseOccupyMask[i, j]; 77 } 78 } 79 for (var j = 0; j < OccupyMask.GetLength(1); ++j) 80 { 81 OccupyMask[OccupyMask.GetLength(0) - 2, j] = true; 82 OccupyMask[OccupyMask.GetLength(0) - 1, j] = true; 83 } 84 } 85 else 86 { 87 OccupyMask = BaseOccupyMask; 88 } 89 } 90 91 public BuildingType(sbyte id, string name, string textId, bool[,] occupyMask, bool hasBib, string ownerHouse, bool isFake, bool hasTurret, string factoryOverlay) 92 : this(id, name, textId, occupyMask, hasBib, ownerHouse, null, isFake, hasTurret, factoryOverlay) 93 { 94 } 95 96 public BuildingType(sbyte id, string name, string textId, bool[,] occupyMask, bool hasBib, string ownerHouse) 97 : this(id, name, textId, occupyMask, hasBib, ownerHouse, null, false, false, null) 98 { 99 } 100 101 public BuildingType(sbyte id, string name, string textId, bool[,] occupyMask, bool hasBib, string ownerHouse, TheaterType[] theaters) 102 : this(id, name, textId, occupyMask, hasBib, ownerHouse, theaters, false, false, null) 103 { 104 } 105 106 public BuildingType(sbyte id, string name, string textId, bool[,] occupyMask, bool hasBib, string ownerHouse, bool isFake) 107 : this(id, name, textId, occupyMask, hasBib, ownerHouse, null, isFake, false, null) 108 { 109 } 110 111 public BuildingType(sbyte id, string name, string textId, bool[,] occupyMask, bool hasBib, string ownerHouse, bool isFake, bool hasTurret) 112 : this(id, name, textId, occupyMask, hasBib, ownerHouse, null, isFake, hasTurret, null) 113 { 114 } 115 116 public override bool Equals(object obj) 117 { 118 if (obj is BuildingType) 119 { 120 return this == obj; 121 } 122 else if (obj is sbyte) 123 { 124 return ID == (sbyte)obj; 125 } 126 else if (obj is string) 127 { 128 return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase); 129 } 130 131 return base.Equals(obj); 132 } 133 134 public override int GetHashCode() 135 { 136 return ID.GetHashCode(); 137 } 138 139 public override string ToString() 140 { 141 return Name; 142 } 143 144 public void Init(GameType gameType, TheaterType theater, HouseType house, DirectionType direction) 145 { 146 var mockBuilding = new Building() 147 { 148 Type = this, 149 House = house, 150 Strength = 256, 151 Direction = direction 152 }; 153 154 var render = MapRenderer.Render(gameType, theater, Point.Empty, Globals.TileSize, Globals.TileScale, mockBuilding); 155 if (!render.Item1.IsEmpty) 156 { 157 var buildingPreview = new Bitmap(render.Item1.Width, render.Item1.Height); 158 using (var g = Graphics.FromImage(buildingPreview)) 159 { 160 render.Item2(g); 161 } 162 Thumbnail = buildingPreview; 163 } 164 } 165 } 166 }