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; } } }
public override void Draw(GameObject obj, DrawingSurface ds, bool shadows = true) { if (InvisibleInGame) { return; } // RA2/YR building rubble if (obj is StructureObject && (obj as StructureObject).Health == 0 && _config.Engine >= EngineType.RedAlert2 && _baseShp.Shp != null) { ShpDrawable rubble = (ShpDrawable)_baseShp.Clone(); rubble.Props = _baseShp.Props.Clone(); rubble.Shp.Initialize(); if (rubble.Shp.NumImages >= 8) { rubble.Props.PaletteOverride = OwnerCollection.Palettes.IsoPalette; rubble.Props.FrameDecider = FrameDeciders.BuildingRubbleFrameDecider(rubble.Shp.NumImages); if (shadows) { rubble.DrawShadow(obj, ds); } rubble.Draw(obj, ds, false); return; } } bool isDamaged = false; bool isOnFire = false; if (obj is StructureObject) { int health = (obj as StructureObject).Health; if (health <= _conditionYellowHealth) { isDamaged = true; if (health > _conditionRedHealth && _canBeOccupied && _techLevel < 1) { isDamaged = false; } } _baseShp.Props.FrameDecider = FrameDeciders.BaseBuildingFrameDecider(isDamaged); if (_config.Engine >= EngineType.RedAlert2) { if (isDamaged) { isOnFire = true; } if (health > _conditionRedHealth && _canBeOccupied) { isOnFire = false; } } } var drawList = new List <Drawable>(); drawList.Add(_baseShp); if (obj is StructureObject && isDamaged) { drawList.AddRange(_animsDamaged); if (isOnFire) { drawList.AddRange(_fires); } } else { drawList.AddRange(_anims); } drawList.AddRange(SubDrawables); // bib /* order: * ActiveAnims+Flat=yes * BibShape * ActiveAnims (+ZAdjust=0) * Building * ActiveAnims+ZAdjust=-32 */ drawList = drawList.OrderBy(d => d.Flat ? -1 : 1).ThenBy(d => d.Props.SortIndex).ToList(); foreach (var d in drawList) { if (shadows) { d.DrawShadow(obj, ds); } d.Draw(obj, ds, false); } var strObj = obj as StructureObject; if (!strObj.Upgrade1.Equals("None", StringComparison.InvariantCultureIgnoreCase)) { AnimDrawable up1 = LoadUpgrade(strObj, 0, Props.Clone()); up1.Draw(obj, ds, false); } if (!strObj.Upgrade2.Equals("None", StringComparison.InvariantCultureIgnoreCase)) { AnimDrawable up2 = LoadUpgrade(strObj, 1, Props.Clone()); up2.Draw(obj, ds, false); } if (!strObj.Upgrade3.Equals("None", StringComparison.InvariantCultureIgnoreCase)) { AnimDrawable up3 = LoadUpgrade(strObj, 2, Props.Clone()); up3.Draw(obj, ds, false); } }