private void Simulate(AnimStage stage = AnimStage.BEFORE_ANIM, bool icons = false) { try { // get regions RegionPolygonBinFile bin = new RegionPolygonBinFile(); bin.ReadFromFile(@"assets\map\points.bin"); Bitmap bmp = new Bitmap(pbPreview.Width, pbPreview.Height); House[] regionOwners = new House[bin.Polygons.Count]; _uibWorkingCopy.GetRegionOwnership(ref regionOwners, (House)_house, _scenario, stage); // paint regions using (Graphics g = Graphics.FromImage(bmp)) { g.DrawImage(new Bitmap(@"assets\map\dunemap2.png"), pbPreview.DisplayRectangle); for (int r = 0; r < bin.Polygons.Count; r++) { RegionPolygonData data = bin.Polygons[r]; Point[] pts = new Point[data.Polygon.Length]; for (int i = 0; i < pts.Length; i++) { pts[i] = data.Polygon[i].ToPoint(); } int owner = (int)regionOwners[r]; if (owner == owner.Clamp(0, 2)) { using (Brush brush = new HatchBrush(HatchStyle.Percent50, Color.FromArgb(0xCF, _houseColors[owner]), Color.Transparent)) { g.FillPolygon(brush, pts); } } using (Pen pen = new Pen(Color.FromArgb(0x7F, Color.Black))) { g.DrawPolygon(pen, pts); } if (icons) { CampaignMissionData currData = _uibWorkingCopy.Houses[_house].Missions[_scenario]; Size sz = new Size(72, 70); if (currData.RegionID1 == r + 1 || currData.RegionID2 == r + 1) { using (Pen pen = new Pen(Color.Blue, 2)) { g.DrawPolygon(pen, pts); } } using (Pen pen = new Pen(Color.DarkBlue)) { using (Brush brush = new SolidBrush(Color.DarkBlue)) { if (currData.RegionID1 > 0) { Point pt = currData.Region1IconPosition.ToPoint(); g.DrawRectangle(pen, new Rectangle(pt, sz)); g.DrawString(currData.MissionFile1, DefaultFont, brush, pt.X + 10, pt.Y + 10); } if (currData.RegionID2 > 0) { Point pt = currData.Region2IconPosition.ToPoint(); g.DrawRectangle(pen, new Rectangle(pt, sz)); g.DrawString(currData.MissionFile2, DefaultFont, brush, pt.X + 10, pt.Y + 10); } } } } using (Brush brush = new SolidBrush(Color.White)) { g.DrawString("{0}, {1}".F(cbHouse.Text, cbScenario.Text), DefaultFont, brush, new Point(5, 5)); } } } pbPreview.Image?.Dispose(); pbPreview.Image = bmp; } catch { } }
public void GetRegionOwnership(ref House[] regionOwners, House playerHouse, int scenario, AnimStage stage) { for (int i = 0; i < regionOwners.Length; i++) { regionOwners[i] = (House)0xFF; } for (int scen = 0; scen < scenario; scen++) { CampaignMissionData data = Houses[(int)playerHouse].Missions[scen]; House[] animOrder = new House[] { data.RegionAnim_House1, data.RegionAnim_House2, data.RegionAnim_House3 }; for (int h = 0; h < animOrder.Length; h++) { if (scen < scenario - 1 || (int)stage > h) { House ihouse = animOrder[h]; if (playerHouse == ihouse) { if (data.RegionID1 > 0 && data.RegionID1 <= regionOwners.Length) { regionOwners[data.RegionID1 - 1] = ihouse; } if (data.RegionID2 > 0 && data.RegionID2 <= regionOwners.Length) { regionOwners[data.RegionID2 - 1] = ihouse; } } switch (ihouse) { case House.ATREIDES: foreach (int r in data.RegionsAwardedToAtreides) { if (r > 0 && r <= regionOwners.Length) { regionOwners[r - 1] = ihouse; } } break; case House.HARKONNEN: foreach (int r in data.RegionsAwardedToHarkonnen) { if (r > 0 && r <= regionOwners.Length) { regionOwners[r - 1] = ihouse; } } break; case House.ORDOS: foreach (int r in data.RegionsAwardedToOrdos) { if (r > 0 && r <= regionOwners.Length) { regionOwners[r - 1] = ihouse; } } break; } } } } }