Пример #1
0
        public override void Draw(GameObject obj, DrawingSurface ds, bool shadows = true)
        {
            terrainShp = new ShpDrawable(_config, _vfs, Rules, Art);
            terrainShp.OwnerCollection = OwnerCollection;
            terrainShp.LoadFromArtEssential();
            terrainShp.Props = Props;
            terrainShp.Shp   = _vfs.Open <ShpFile>(terrainShp.GetFilename());

            foreach (var sub in SubDrawables.OfType <AlphaDrawable>())
            {
                sub.Draw(obj, ds, false);
            }

            if (shadows)
            {
                terrainShp.DrawShadow(obj, ds);
            }
            terrainShp.Draw(obj, ds, false);
        }
Пример #2
0
        public override void LoadFromRules()
        {
            base.LoadFromRules();

            IsBuildingPart  = true;
            InvisibleInGame = Rules.ReadBool("InvisibleInGame") || LampNames.Contains(Name.ToUpper());
            string foundation = Art.ReadString("Foundation", "1x1");

            if (!foundation.Equals("custom", StringComparison.InvariantCultureIgnoreCase))
            {
                int fx = foundation[0] - '0';
                int fy = foundation[2] - '0';
                Foundation = new Size(fx, fy);
            }
            else
            {
                int fx = Art.ReadInt("Foundation.X", 1);
                int fy = Art.ReadInt("Foundation.Y", 1);
                Foundation = new Size(fx, fy);
            }
            Props.SortIndex       = Art.ReadInt("NormalYSort") - Art.ReadInt("NormalZAdjust");       // "main" building image before anims
            Props.ZShapePointMove = Art.ReadPoint("ZShapePointMove");

            _canBeOccupied         = Rules.ReadBool("CanBeOccupied");
            _techLevel             = Rules.ReadInt("TechLevel");
            _conditionYellowHealth = 128;
            _conditionRedHealth    = 64;
            IniFile.IniSection audioVisual = OwnerCollection.Rules.GetOrCreateSection("AudioVisual");
            if (audioVisual != null)
            {
                if (audioVisual.HasKey("ConditionYellow"))
                {
                    int conditionYellow = audioVisual.ReadPercent("ConditionYellow");
                    _conditionYellowHealth = (int)(256 * (double)conditionYellow / 100);
                }
                if (audioVisual.HasKey("ConditionRed"))
                {
                    int conditionRed = audioVisual.ReadPercent("ConditionRed");
                    _conditionRedHealth = (int)(256 * (double)conditionRed / 100);
                }
            }
            _baseShp = new ShpDrawable(_config, _vfs, Rules, Art);
            _baseShp.OwnerCollection = OwnerCollection;
            _baseShp.LoadFromArtEssential();
            _baseShp.Props = Props;
            _baseShp.Shp   = _vfs.Open <ShpFile>(_baseShp.GetFilename());

            var extraProps = Props.Clone();

            extraProps.SortIndex = 0;
            foreach (string extraImage in AnimImages)
            {
                var extra = LoadExtraImage(extraImage, extraProps);
                if (extra != null && extra.Shp != null)
                {
                    _anims.Add(extra);

                    var extraDmg = LoadExtraImage(extraImage + "Damaged", extra.Props);
                    if (extraDmg != null && extraDmg.Shp != null)
                    {
                        _animsDamaged.Add(extraDmg);
                    }
                    else                     // no damaged anim --> use normal anim also in damaged state
                    {
                        _animsDamaged.Add(extra);
                    }
                }
            }

            // RA2 and later support adding fire animations to buildings, supports custom-paletted animations.
            if (_config.Engine >= EngineType.RedAlert2)
            {
                LoadFireAnimations();
            }

            // Add turrets
            if (Rules.ReadBool("Turret") && Rules.HasKey("TurretAnim"))
            {
                string             turretName = Rules.ReadString("TurretAnim");
                IniFile.IniSection turretArt  = OwnerCollection.Art.GetOrCreateSection(turretName);
                if (turretArt.HasKey("Image"))
                {
                    turretName = turretArt.ReadString("Image");
                }
                // NewTheater/generic image fallback support for turrets.
                string   turretNameShp = NewTheater ? OwnerCollection.ApplyNewTheaterIfNeeded(turretName, turretName + ".shp") : turretName + ".shp";
                Drawable turret        = Rules.ReadBool("TurretAnimIsVoxel")
                                        ? (Drawable) new VoxelDrawable(_config, _vfs.Open <VxlFile>(turretName + ".vxl"), _vfs.Open <HvaFile>(turretName + ".hva"))
                                        : (Drawable) new ShpDrawable(new ShpRenderer(_config, _vfs), _vfs.Open <ShpFile>(turretNameShp));
                turret.Props.Offset       = Props.Offset + new Size(Rules.ReadInt("TurretAnimX"), Rules.ReadInt("TurretAnimY"));
                turret.Props.HasShadow    = Rules.ReadBool("UseTurretShadow");
                turret.Props.FrameDecider = FrameDeciders.TurretFrameDecider;
                turret.Props.ZAdjust      = Rules.ReadInt("TurretAnimZAdjust");
                turret.Props.Cloakable    = Props.Cloakable;
                SubDrawables.Add(turret);

                if (turret is VoxelDrawable && turretName.ToUpper().Contains("TUR"))
                {
                    string barrelName = turretName.Replace("TUR", "BARL");
                    if (_vfs.FileExists(barrelName + ".vxl"))
                    {
                        var barrel = new VoxelDrawable(_config, _vfs.Open <VxlFile>(barrelName + ".vxl"), _vfs.Open <HvaFile>(barrelName + ".hva"));
                        SubDrawables.Add(barrel);
                        barrel.Props = turret.Props;
                    }
                }
            }

            // Bib
            if (Art.HasKey("BibShape"))
            {
                var bibImg = Art.ReadString("BibShape") + ".shp";
                if (NewTheater)
                {
                    bibImg = OwnerCollection.ApplyNewTheaterIfNeeded(bibImg, bibImg);
                }
                var bibShp = _vfs.Open <ShpFile>(bibImg);
                if (bibShp != null)
                {
                    var bib = new ShpDrawable(new ShpRenderer(_config, _vfs), bibShp);
                    bib.Props = this.Props.Clone();
                    bib.Flat  = true;
                    SubDrawables.Add(bib);
                }
            }

            // Powerup slots, at most 3
            for (int i = 1; i <= 3; i++)
            {
                _powerupSlots.Add(new PowerupSlot {
                    X     = Art.ReadInt(String.Format("PowerUp{0}LocXX", i), 0),
                    Y     = Art.ReadInt(String.Format("PowerUp{0}LocYY", i), 0),
                    Z     = Art.ReadInt(String.Format("PowerUp{0}LocZZ", i), 0),
                    YSort = Art.ReadInt(String.Format("PowerUp{0}LocYSort", i), 0),
                });
            }

            if (IsWall && _baseShp.Shp != null)
            {
                _baseShp.Shp.Initialize();
                if (_baseShp.Shp.NumImages >= 32)
                {
                    IsActualWall = true;
                }
            }
        }