private AnimDrawable LoadUpgrade(StructureObject structObj, int upgradeSlot, DrawProperties inheritProps) { string upgradeName = ""; if (upgradeSlot == 0) { upgradeName = structObj.Upgrade1; } else if (upgradeSlot == 1) { upgradeName = structObj.Upgrade2; } else if (upgradeSlot == 2) { upgradeName = structObj.Upgrade3; } IniFile.IniSection upgradeRules = OwnerCollection.Rules.GetOrCreateSection(upgradeName); if (upgradeRules != null && upgradeRules.HasKey("Image")) { upgradeName = upgradeRules.ReadString("Image"); } IniFile.IniSection upgradeArt = OwnerCollection.Art.GetOrCreateSection(upgradeName); if (upgradeArt != null && upgradeArt.HasKey("Image")) { upgradeName = upgradeArt.ReadString("Image"); } IniFile.IniSection upgRules = OwnerCollection.Rules.GetOrCreateSection(upgradeName); IniFile.IniSection upgArt = OwnerCollection.Art.GetOrCreateSection(upgradeName); AnimDrawable upgrade = new AnimDrawable(_config, _vfs, upgRules, upgArt); upgrade.OwnerCollection = OwnerCollection; upgrade.Props = inheritProps; upgrade.LoadFromRules(); upgrade.NewTheater = this.NewTheater; upgrade.IsBuildingPart = true; string shpfilename = NewTheater ? OwnerCollection.ApplyNewTheaterIfNeeded(upgradeName, upgradeName + ".shp") : upgradeName + ".shp"; upgrade.Shp = _vfs.Open <ShpFile>(shpfilename); Point powerupOffset = new Point(_powerupSlots[upgradeSlot].X, _powerupSlots[upgradeSlot].Y); upgrade.Props.Offset.Offset(powerupOffset); return(upgrade); }
private AnimDrawable LoadExtraImage(string extraImage, DrawProperties inheritProps) { string animSection = Art.ReadString(extraImage); if (animSection == "") { return(null); } IniFile.IniSection extraRules = OwnerCollection.Rules.GetOrCreateSection(animSection); IniFile.IniSection extraArt = OwnerCollection.Art.GetOrCreateSection(animSection); var anim = new AnimDrawable(_config, _vfs, extraRules, extraArt); anim.OwnerCollection = OwnerCollection; anim.LoadFromRules(); anim.NewTheater = this.NewTheater; if (extraArt.HasKey("YSortAdjust") || Art.HasKey(extraImage + "YSort") || extraArt.HasKey("ZAdjust") || Art.HasKey(extraImage + "ZAdjust")) { anim.Props.SortIndex = extraArt.ReadInt("YSortAdjust", Art.ReadInt(extraImage + "YSort")) - extraArt.ReadInt("ZAdjust", Art.ReadInt(extraImage + "ZAdjust")); } else { anim.Props.SortIndex = inheritProps.SortIndex; } if (Art.HasKey(extraImage + "X") || Art.HasKey(extraImage + "Y")) { anim.Props.Offset = this.Props.Offset + new Size(Art.ReadInt(extraImage + "X"), Art.ReadInt(extraImage + "Y")); } else { anim.Props.Offset = inheritProps.Offset; } anim.Props.ZAdjust = Art.ReadInt(extraImage + "ZAdjust"); anim.IsBuildingPart = true; anim.Shp = _vfs.Open <ShpFile>(anim.GetFilename()); return(anim); }
// Adds fire animations to a building. Supports custom-paletted animations. private void LoadFireAnimations() { // http://modenc.renegadeprojects.com/DamageFireTypes int f = 0; while (true) // enumerate as many fires as are existing { string dfo = Art.ReadString("DamageFireOffset" + f++); if (dfo == "") { break; } string[] coords = dfo.Split(new[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries); string fireAnim = OwnerCollection.FireNames[Rand.Next(OwnerCollection.FireNames.Length)]; IniFile.IniSection fireArt = OwnerCollection.Art.GetOrCreateSection(fireAnim); var fire = new AnimDrawable(_config, _vfs, Rules, Art, _vfs.Open <ShpFile>(fireAnim + ".shp")); fire.Props.PaletteOverride = GetFireAnimPalette(fireArt); fire.Props.Offset = new Point(Int32.Parse(coords[0]) + (_config.TileWidth / 2), Int32.Parse(coords[1])); fire.Props.FrameDecider = FrameDeciders.RandomFrameDecider; _fires.Add(fire); } }
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); } }