CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

TerrainType.cs (4170B)


      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.Utility;
     17 using System;
     18 using System.Drawing;
     19 
     20 namespace MobiusEditor.Model
     21 {
     22     public class TerrainType : ICellOverlapper, ICellOccupier, IBrowsableType
     23     {
     24         public sbyte ID { get; private set; }
     25 
     26         public string Name { get; private set; }
     27 
     28         public string DisplayName => Name;
     29 
     30         public Rectangle OverlapBounds => new Rectangle(
     31             Point.Empty,
     32             new Size(((RenderSize.Width + Globals.TileWidth - 1) / Globals.TileWidth), ((RenderSize.Height + Globals.TileHeight - 1) / Globals.TileHeight))
     33         );
     34 
     35         public bool[,] OccupyMask { get; private set; }
     36 
     37         public Size Size => new Size(OccupyMask.GetLength(1), OccupyMask.GetLength(0));
     38 
     39         public TheaterType[] Theaters { get; private set; }
     40 
     41         public bool IsTransformable { get; private set; }
     42 
     43         public TemplateTypeFlag TemplateType { get; private set; }
     44 
     45         public Size RenderSize { get; set; }
     46 
     47         public Image Thumbnail { get; set; }
     48 
     49         public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask, bool isTransformable, TemplateTypeFlag templateType)
     50         {
     51             ID = id;
     52             Name = name;
     53             Theaters = theaters;
     54             OccupyMask = occupyMask;
     55             IsTransformable = isTransformable;
     56             TemplateType = templateType;
     57         }
     58 
     59         public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask, bool isTransformable)
     60             : this(id, name, theaters, occupyMask, isTransformable, TemplateTypeFlag.None)
     61         {
     62         }
     63 
     64         public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask, TemplateTypeFlag templateType)
     65             : this(id, name, theaters, occupyMask, false, templateType)
     66         {
     67         }
     68 
     69         public TerrainType(sbyte id, string name, TheaterType[] theaters, bool[,] occupyMask)
     70             : this(id, name, theaters, occupyMask, false, TemplateTypeFlag.None)
     71         {
     72         }
     73 
     74         public override bool Equals(object obj)
     75         {
     76             if (obj is TerrainType)
     77             {
     78                 return this == obj;
     79             }
     80             else if (obj is sbyte)
     81             {
     82                 return ID == (sbyte)obj;
     83             }
     84             else if (obj is string)
     85             {
     86                 return string.Equals(Name, obj as string, StringComparison.OrdinalIgnoreCase);
     87             }
     88 
     89             return base.Equals(obj);
     90         }
     91 
     92         public override int GetHashCode()
     93         {
     94             return ID.GetHashCode();
     95         }
     96 
     97         public override string ToString()
     98         {
     99             return Name;
    100         }
    101 
    102         public void Init(TheaterType theater)
    103         {
    104             string tileName = Name;
    105             if ((TemplateType & TemplateTypeFlag.OreMine) != TemplateTypeFlag.None)
    106             {
    107                 tileName = "OREMINE";
    108             }
    109 
    110             if (Globals.TheTilesetManager.GetTileData(theater.Tilesets, tileName, IsTransformable ? 22 : 0, out Tile tile))
    111             {
    112                 RenderSize = new Size(tile.Image.Width / Globals.TileScale, tile.Image.Height / Globals.TileScale);
    113                 Thumbnail = new Bitmap(tile.Image, tile.Image.Width / 2, tile.Image.Height / 2);
    114             }
    115         }
    116     }
    117 }