MapCode.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. // This code determines the cell values for
  17. // StartX, StartY, Width & Height for the [Header] section
  18. #include "stdafx.h"
  19. #include "MapCode.h"
  20. #include "mapdata.h"
  21. #include "defines.h"
  22. int calcXPos(int x, int y)
  23. {
  24. int x1=x*256+128;
  25. int y1 = y*256 + 128;
  26. int x2 = (x1 - y1) * 30;
  27. int y2 = (x1 + y1) * 15;
  28. int x3 = (x2/256 + 512*30) / 60;
  29. int y3 = (y2/256) / 30;
  30. return x3;
  31. }
  32. int calcYPos(int x, int y)
  33. {
  34. int x1=x*256+128;
  35. int y1 = y*256 + 128;
  36. int x2 = (x1 - y1) * 30;
  37. int y2 = (x1 + y1) * 15;
  38. int x3 = (x2/256 + 512*30) / 60;
  39. int y3 = (y2/256) / 30;
  40. return y3;
  41. }
  42. struct MRECT
  43. {
  44. int X;
  45. int Y;
  46. int Width;
  47. int Height;
  48. };
  49. void MC_GetHeaderRect(int& startx, int& starty, int& width, int& height)
  50. {
  51. int leastx=10000;
  52. int leasty=10000;
  53. int mostx=0;
  54. int mosty=0;
  55. MRECT LocalRect, PlayRect;
  56. RECT r;
  57. Map->GetLocalSize(&r);
  58. LocalRect.X=r.left;
  59. LocalRect.Y=r.top;
  60. LocalRect.Width=r.right;
  61. LocalRect.Height=r.bottom;
  62. CIniFile& ini=Map->GetIniFile();
  63. PlayRect.X=0;
  64. PlayRect.Y=0;
  65. PlayRect.Width=Map->GetWidth();
  66. PlayRect.Height=Map->GetHeight();
  67. char c[50];
  68. char d[50];
  69. itoa(LocalRect.Width, c, 10);
  70. int x,y;
  71. int max=Map->GetIsoSize();
  72. for(x=0;x<max;x++)
  73. {
  74. for(y=0;y<max;y++)
  75. {
  76. int height=0;
  77. if (TRUE) {
  78. height = Map->GetHeightAt(y+x*max); // remember: x/y switched here, WS coordinate system
  79. // fudge ramps at the top of the map so that they end up considered not in the local rect
  80. //if (cell->ramp && x + y < PlayRect.Width + 2*LocalRect.Y + 4 + height) {
  81. //height++;
  82. //}
  83. }
  84. if ((x + y > PlayRect.Width + 2*LocalRect.Y + height) &&
  85. (x + y <= PlayRect.Width + 2*(LocalRect.Y + LocalRect.Height + 1) + height) &&
  86. (x - y < 2*(LocalRect.X + LocalRect.Width) - PlayRect.Width) &&
  87. (y - x < PlayRect.Width - 2*LocalRect.X))
  88. //if ((x + y > PlayRect.Width) && (x - y < PlayRect.Width) && (y - x < PlayRect.Width) && (x + y <= PlayRect.Width + 2 * PlayRect.Height))
  89. {
  90. int rx=calcXPos(x,y);
  91. int ry=calcYPos(x,y);
  92. if (rx < leastx)
  93. leastx = rx;
  94. if (rx > mostx)
  95. mostx = rx;
  96. if (ry < leasty)
  97. leasty = ry;
  98. if (ry > mosty)
  99. mosty = ry;
  100. }
  101. }
  102. }
  103. startx=leastx;
  104. starty=leasty;
  105. width=mostx-leastx;
  106. height=mosty-leasty;
  107. }