public MapStructure(string name) { Class = StructureClassLoader.GetStructureClassByName(name); if (Class == null) { Debug.LogFormat("Invalid structure created (name={0})", name); } else { InitStructure(); } }
public MapStructure(int typeId) { Class = StructureClassLoader.GetStructureClassById(typeId); if (Class == null) { Debug.LogFormat("Invalid structure created (typeId={0})", typeId); } else { InitStructure(); } }
private void InitStructure() { Template = TemplateLoader.GetStructureById(Class.ID); if (Template == null) { Debug.LogFormat("Invalid structure created (template not found, typeId={0})", Class.ID); Class = null; return; } HealthMax = Health = Template.HealthMax; Width = Template.Width; Height = Template.Height; ScanRange = Template.ScanRange; // only default scanrange DoUpdateView = true; }
public void OnUpdate() { if (Renderer == null) { return; } if (LogicStructure.GetVisibility() == 0) { oldVisibility = false; Renderer.enabled = false; OverlayRenderer.enabled = false; if (ShadowRenderer != null) { ShadowRenderer.enabled = false; } return; } else if (!oldVisibility && !LogicStructure.DoUpdateView) { Renderer.enabled = true; OverlayRenderer.enabled = true; if (ShadowRenderer != null) { ShadowRenderer.enabled = true; } oldVisibility = true; return; } if (LogicStructure.DoUpdateView) { Renderer.enabled = true; OverlayRenderer.enabled = true; if (ShadowRenderer != null) { ShadowRenderer.enabled = true; } StructureClass cls = LogicStructure.Class; Images.AllodsSprite sprites = LogicStructure.Class.File.File; Images.AllodsSprite spritesB = LogicStructure.Class.File.FileB; if (sprites == null) { LogicStructure.Class.File.UpdateSprite(); sprites = LogicStructure.Class.File.File; spritesB = LogicStructure.Class.File.FileB; } if (!MapView.Instance.SpritesBEnabled) { spritesB = null; } int newMaterialCount = (spritesB != null) ? 2 : 1; if (!spriteSet || Renderer.materials.Length != newMaterialCount) { List <Material> newMats = new List <Material>(); List <Material> newMatsShadow = new List <Material>(); List <Material> newMatsOverlay = new List <Material>(); for (int i = 0; i < newMaterialCount; i++) { newMats.Add(new Material(MainCamera.MainShaderPaletted)); newMatsOverlay.Add(new Material(MainCamera.MainShaderPaletted)); if (ShadowRenderer != null) { newMatsShadow.Add(new Material(MainCamera.MainShaderPaletted)); } } Renderer.materials = newMats.ToArray(); OverlayRenderer.materials = newMatsOverlay.ToArray(); if (ShadowRenderer != null) { ShadowRenderer.materials = newMats.ToArray(); } for (int i = 0; i < newMaterialCount; i++) { Renderer.materials[i].SetTexture("_Palette", sprites.OwnPalette); Renderer.materials[i].SetFloat("_Lightness", 1f); OverlayRenderer.materials[i].SetTexture("_Palette", sprites.OwnPalette); OverlayRenderer.materials[i].SetFloat("_Lightness", 1f); if (ShadowRenderer != null) { ShadowRenderer.materials[i].SetTexture("_Palette", sprites.OwnPalette); ShadowRenderer.materials[i].color = new Color(0, 0, 0, 0.5f); } } spriteSet = true; } int actualFrame = cls.Frames[LogicStructure.CurrentFrame].Frame; Vector2 xP = MapView.Instance.MapToScreenCoords(LogicObject.X + 0.5f, LogicObject.Y + 0.5f, LogicStructure.Width, LogicStructure.Height); transform.localPosition = new Vector3(xP.x - 16, xP.y - 16 - (cls.FullHeight - cls.TileHeight) * 32, MakeZFromY(xP.y) + 4); if (LogicStructure.Class.VariableSize) { StructureMesh = UpdateMesh(sprites, spritesB, 0, Filter.mesh, 0, 0, LogicStructure.Width, LogicStructure.Height, 0, (StructureMesh == null), false); } else { StructureMesh = UpdateMesh(sprites, spritesB, actualFrame, Filter.mesh, 0, cls.FullHeight - cls.TileHeight, cls.TileWidth, cls.TileHeight, 0, (StructureMesh == null), false); OverlayMesh = UpdateMesh(sprites, spritesB, actualFrame, OverlayFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight - cls.TileHeight, 0, (OverlayMesh == null), false); if (ShadowFilter != null) { ShadowMesh = UpdateMesh(sprites, spritesB, actualFrame, ShadowFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight, 0.3f, (ShadowMesh == null), false); } } LogicStructure.DoUpdateView = false; } }
public static void InitClasses() { if (ClassesLoaded) { return; } ClassesLoaded = true; Registry reg = new Registry("graphics/structures/structures.reg"); int ObjectCount = reg.GetInt("Global", "Count", 0); for (int i = 0; i < ObjectCount; i++) { string on = string.Format("Structure{0}", i); StructureClass cls = new StructureClass(); cls.DescText = reg.GetString(on, "DescText", ""); cls.ID = reg.GetInt(on, "ID", -1); string file = reg.GetString(on, "File", null); if (file != null) { StructureFile sfile = new StructureFile(); sfile.FileName = "graphics/structures/" + file; cls.File = sfile; } cls.TileWidth = reg.GetInt(on, "TileWidth", 1); cls.TileHeight = reg.GetInt(on, "TileHeight", 1); cls.FullHeight = reg.GetInt(on, "FullHeight", cls.TileHeight); cls.SelectionX1 = reg.GetInt(on, "SelectionX1", 0); cls.SelectionY1 = reg.GetInt(on, "SelectionY1", 0); cls.SelectionX2 = reg.GetInt(on, "SelectionX2", cls.TileWidth * 32); cls.SelectionY2 = reg.GetInt(on, "SelectionY2", cls.FullHeight * 32); cls.ShadowY = reg.GetInt(on, "ShadowY", 0); if (cls.ShadowY < 0) // this is very bad. this means that Nival artists were trying to make this structure Flat, but didn't know about the feature. { // as such, they were setting ShadowY -20000 and the shadow was still appearing sometimes despite LOOKING AS IF it was flat. cls.Flat = true; cls.ShadowY = 0; } // also this fixes Bee houses if (cls.ShadowY > cls.FullHeight * 32) { cls.ShadowY = 0; } cls.AnimMask = reg.GetString(on, "AnimMask", null); int phases = reg.GetInt(on, "Phases", 1); if (phases == 1) { cls.Frames = new StructureClass.AnimationFrame[1]; cls.Frames[0].Frame = 0; cls.Frames[0].Time = 0; } else { int[] animFrame = reg.GetArray(on, "AnimFrame", null); int[] animTime = reg.GetArray(on, "AnimTime", null); if (animFrame == null || animTime == null || animFrame.Length != animTime.Length) { // some structures already have invalid definitions. cls.Frames = new StructureClass.AnimationFrame[1]; cls.Frames[0].Frame = 0; cls.Frames[0].Time = 0; } else { cls.Frames = new StructureClass.AnimationFrame[animFrame.Length]; for (int j = 0; j < animFrame.Length; j++) { cls.Frames[j].Frame = animFrame[j]; cls.Frames[j].Time = animTime[j]; } } } cls.Picture = "graphics/infowindow/" + reg.GetString(on, "Picture", "") + ".bmp"; cls.IconID = reg.GetInt(on, "IconID", StructureClass.MagicIntNull); cls.Indestructible = reg.GetInt(on, "Indestructible", 0) != 0; cls.Usable = reg.GetInt(on, "Usable", 0) != 0; cls.Flat = reg.GetInt(on, "Flat", 0) != 0; cls.VariableSize = reg.GetInt(on, "VariableSize", 0) != 0; cls.LightRadius = reg.GetInt(on, "LightRadius", 0); cls.LightPulse = reg.GetInt(on, "LightPulse", 0); Classes.Add(cls); } }
public void OnUpdate() { if (Renderer == null) { return; } if (LogicStructure.GetVisibility() == 0) { oldVisibility = false; Renderer.enabled = false; OverlayRenderer.enabled = false; if (ShadowRenderer != null) { ShadowRenderer.enabled = false; } return; } else if (!oldVisibility && !LogicStructure.DoUpdateView) { Renderer.enabled = true; OverlayRenderer.enabled = true; if (ShadowRenderer != null) { ShadowRenderer.enabled = true; } oldVisibility = true; return; } if (LogicStructure.DoUpdateView) { Renderer.enabled = true; OverlayRenderer.enabled = true; if (ShadowRenderer != null) { ShadowRenderer.enabled = true; } StructureClass cls = LogicStructure.Class; Images.AllodsSprite sprites = LogicStructure.Class.File.File; if (!spriteSet) { LogicStructure.Class.File.UpdateSprite(); sprites = LogicStructure.Class.File.File; Renderer.material = LogicStructure.Class.File.FileMaterial; Renderer.material.SetTexture("_Palette", sprites.OwnPalette); Renderer.material.SetFloat("_Lightness", 1f); OverlayRenderer.material = LogicStructure.Class.File.FileMaterial; OverlayRenderer.material.SetTexture("_Palette", sprites.OwnPalette); OverlayRenderer.material.SetFloat("_Lightness", 1f); if (ShadowRenderer != null) { ShadowRenderer.material = LogicStructure.Class.File.FileMaterial; ShadowRenderer.material.SetTexture("_Palette", sprites.OwnPalette); ShadowRenderer.material.color = new Color(0, 0, 0, 0.5f); } spriteSet = true; } int actualFrame = cls.Frames[LogicStructure.CurrentFrame].Frame; Vector2 xP = MapView.Instance.MapToScreenCoords(LogicObject.X + 0.5f, LogicObject.Y + 0.5f, LogicStructure.Width, LogicStructure.Height); transform.localPosition = new Vector3(xP.x - 16, xP.y - 16 - (cls.FullHeight - cls.TileHeight) * 32, MakeZFromY(xP.y) + 4); if (LogicStructure.Class.VariableSize) { StructureMesh = UpdateMesh(sprites, 0, Filter.mesh, 0, 0, LogicStructure.Width, LogicStructure.Height, 0, (StructureMesh == null), false); } else { StructureMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, cls.FullHeight - cls.TileHeight, cls.TileWidth, cls.TileHeight, 0, (StructureMesh == null), false); OverlayMesh = UpdateMesh(sprites, actualFrame, OverlayFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight - cls.TileHeight, 0, (OverlayMesh == null), false); if (ShadowFilter != null) { ShadowMesh = UpdateMesh(sprites, actualFrame, ShadowFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight, 0.3f, (ShadowMesh == null), false); } } LogicStructure.DoUpdateView = false; } else if (Renderer != null) { StructureClass cls = LogicStructure.Class; Images.AllodsSprite sprites = LogicStructure.Class.File.File; int actualFrame = LogicStructure.Class.Frames[LogicStructure.CurrentFrame].Frame; StructureMesh = UpdateMesh(sprites, actualFrame, Filter.mesh, 0, cls.FullHeight - cls.TileHeight, cls.TileWidth, cls.TileHeight, 0, (StructureMesh == null), false); OverlayMesh = UpdateMesh(sprites, actualFrame, OverlayFilter.mesh, 0, 0, cls.TileWidth, cls.FullHeight - cls.TileHeight, 0, (OverlayMesh == null), false); } }