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); }
public override void LoadFromRules() { base.LoadFromArtEssential(); ShpDrawable shp = null; VoxelDrawable vxl = null; if (IsVoxel) { vxl = new VoxelDrawable(_config, _vfs, Rules, Art); vxl.OwnerCollection = OwnerCollection; vxl.Props = Props; vxl.LoadFromRules(); vxl.Vxl = _vfs.Open <VxlFile>(vxl.Image + ".vxl"); vxl.Hva = _vfs.Open <HvaFile>(vxl.Image + ".hva"); SubDrawables.Add(vxl); } else { shp = new ShpDrawable(_config, _vfs, Rules, Art); shp.Props = Props; shp.OwnerCollection = OwnerCollection; shp.LoadFromRules(); shp.Shp = _vfs.Open <ShpFile>(shp.GetFilename()); shp.Props.FrameDecider = FrameDeciders.SHPVehicleFrameDecider(shp.StartStandFrame, shp.StandingFrames, shp.StartWalkFrame, shp.WalkFrames, shp.Facings, _config.Engine); SubDrawables.Add(shp); } if (shp != null || vxl != null) { if (Rules.ReadBool("Turret")) { VoxelDrawable vxlturret = null; ShpDrawable shpturret = null; var turretVxl = _vfs.Open <VxlFile>(Image + "TUR.vxl"); var turretHva = _vfs.Open <HvaFile>(Image + "TUR.hva"); if (turretVxl != null && turretHva != null) { vxlturret = new VoxelDrawable(_config, turretVxl, turretHva); vxlturret.Props.Offset = Props.Offset; vxlturret.Props.Offset += new Size(Rules.ReadInt("TurretAnimX"), Rules.ReadInt("TurretAnimY")); vxlturret.Props.TurretVoxelOffset = Art.ReadFloat("TurretOffset"); vxlturret.Props.Cloakable = Props.Cloakable; SubDrawables.Add(vxlturret); } if (vxlturret == null && shp != null) { shpturret = new ShpDrawable(_config, _vfs, Rules, Art); shpturret.Props = (DrawProperties)shp.Props.Clone(); shpturret.OwnerCollection = OwnerCollection; shpturret.LoadFromRules(); shpturret.Shp = _vfs.Open <ShpFile>(shpturret.GetFilename()); shpturret.Props.FrameDecider = FrameDeciders.SHPVehicleSHPTurretFrameDecider(shpturret.StartWalkFrame, shpturret.WalkFrames, shpturret.Facings); shpturret.Props.Cloakable = Props.Cloakable; SubDrawables.Add(shpturret); } var barrelVxl = _vfs.Open <VxlFile>(Image + "BARL.vxl"); var barrelHva = _vfs.Open <HvaFile>(Image + "BARL.hva"); if (barrelVxl != null && barrelHva != null) { var barrel = new VoxelDrawable(_config, barrelVxl, barrelHva); if (vxlturret != null) { barrel.Props = vxlturret.Props; } else if (shp != null) { barrel.Props.Offset = Props.Offset; barrel.Props.Offset += new Size(Rules.ReadInt("TurretAnimX"), Rules.ReadInt("TurretAnimY")); barrel.Props.TurretVoxelOffset = Art.ReadFloat("TurretOffset"); } barrel.Props.Cloakable = Props.Cloakable; SubDrawables.Add(barrel); } } } }
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; } } }