GETSHAPE.CPP 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  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. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : Westwood Library *
  23. * *
  24. * File Name : GETSHAPE.CPP *
  25. * *
  26. * Programmer : Joe L. Bostic *
  27. * *
  28. * Start Date : April 5, 1992 *
  29. * *
  30. * Last Update : May 25, 1994 [BR] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * Functions: *
  34. * Get_Shape_Size -- Fetch the size of the shape in memory. *
  35. * Get_Shape_Uncomp_Size -- gets shape's uncompressed size in bytes *
  36. * Get_Shape_Data -- retrieves a shape's special prefix data *
  37. * Extract_Shape_Count -- returns # of shapes in the given shape block *
  38. * Extract_Shape -- Gets pointer to shape in given shape block *
  39. * Get_Shape_Width -- gets shape width in pixels *
  40. * Get_Shape_Height -- gets shape height in pixels *
  41. * Set_Shape_Height -- modifies shape's height *
  42. * Restore_Shape_Height -- restores a shape to its original height *
  43. * Get_Shape_Original_Height -- gets shape's unmodified height *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. /*
  46. ********************************* Includes **********************************
  47. */
  48. #include "wwstd.h"
  49. #include "shape.h"
  50. /***************************************************************************
  51. * Get_Shape_Size -- Fetch the size of the shape in memory. *
  52. * *
  53. * The shape size returned includes both the shape header & its data. *
  54. * *
  55. * INPUT: *
  56. * shape pointer to shape *
  57. * *
  58. * OUTPUT: *
  59. * shape's size in memory *
  60. * *
  61. * WARNINGS: *
  62. * none *
  63. * *
  64. * HISTORY: *
  65. * 06/09/1992 JLB : Created. *
  66. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  67. * 05/25/1994 BR : Converted to 32-bit *
  68. *=========================================================================*/
  69. int cdecl Get_Shape_Size(VOID const *shape)
  70. {
  71. Shape_Type *shp = (Shape_Type *)shape;
  72. /*
  73. ------------------------- Return if NULL pointer -------------------------
  74. */
  75. if (!shape)
  76. return(0);
  77. /*
  78. -------------------------- Returns shape's size --------------------------
  79. */
  80. return (shp->ShapeSize);
  81. } /* end of Get_Shape_Size */
  82. /***************************************************************************
  83. * Get_Shape_Uncomp_Size -- gets shape's uncompressed size in bytes *
  84. * *
  85. * INPUT: *
  86. * shape pointer to shape *
  87. * *
  88. * OUTPUT: *
  89. * shape's size in bytes when uncompressed *
  90. * *
  91. * WARNINGS: *
  92. * none *
  93. * *
  94. * HISTORY: *
  95. * 06/09/1992 JLB : Created. *
  96. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  97. * 05/25/1994 BR : Converted to 32-bit *
  98. *=========================================================================*/
  99. int Get_Shape_Uncomp_Size(VOID const *shape)
  100. {
  101. Shape_Type *shp = (Shape_Type *)shape;
  102. return (shp->DataLength);
  103. } /* end of Get_Shape_Uncomp_Size */
  104. /***************************************************************************
  105. * Get_Shape_Data -- retrieves a shape's special prefix data *
  106. * *
  107. * MAKESHPS.EXE can store special data values along with a shape. These *
  108. * values are inserted in the shape table >before< the shape's header. *
  109. * So, this routine uses the 'data' parameter as a negative index from *
  110. * the given shape pointer. *
  111. * *
  112. * INPUT: *
  113. * shape pointer to shape *
  114. * data index of WORD data value to get *
  115. * *
  116. * OUTPUT: *
  117. * data value *
  118. * *
  119. * WARNINGS: *
  120. * The shape pointer must be a pointer into a shape table created by *
  121. * MAKESHPS.EXE; it >cannot< be a pointer to shape returned by Make_Shape! *
  122. * *
  123. * HISTORY: *
  124. * 06/09/1992 JLB : Created. *
  125. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  126. * 05/25/1994 BR : Converted to 32-bit *
  127. *=========================================================================*/
  128. WORD cdecl Get_Shape_Data(VOID const *shape, WORD data)
  129. {
  130. WORD *word_ptr = (WORD *)shape;
  131. WORD retval;
  132. retval = *(word_ptr - (data+1));
  133. return (retval);
  134. } /* end of Get_Shape_Data */
  135. /***************************************************************************
  136. * Extract_Shape_Count -- returns # of shapes in the given shape block *
  137. * *
  138. * The # of shapes in a shape block is the first WORD in the block, so *
  139. * this is the value returned. *
  140. * *
  141. * INPUT: *
  142. * buffer pointer to shape block, created with MAKESHPS.EXE *
  143. * *
  144. * OUTPUT: *
  145. * # shapes in the block *
  146. * *
  147. * WARNINGS: *
  148. * none *
  149. * *
  150. * HISTORY: *
  151. * 06/09/1992 JLB : Created. *
  152. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  153. * 05/25/1994 BR : Converted to 32-bit *
  154. *=========================================================================*/
  155. int cdecl Extract_Shape_Count(VOID const *buffer)
  156. {
  157. ShapeBlock_Type *block = (ShapeBlock_Type *)buffer;
  158. return (block->NumShapes);
  159. } /* end of Extract_Shape_Count */
  160. /***************************************************************************
  161. * Extract_Shape -- Gets pointer to shape in given shape block *
  162. * *
  163. * INPUT: *
  164. * buffer pointer to shape block, created with MAKESHPS.EXE *
  165. * shape index of shape to get *
  166. * *
  167. * OUTPUT: *
  168. * pointer to shape in the shape block *
  169. * *
  170. * WARNINGS: *
  171. * none *
  172. * *
  173. * HISTORY: *
  174. * 06/09/1992 JLB : Created. *
  175. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  176. * 05/25/1994 BR : Converted to 32-bit *
  177. *=========================================================================*/
  178. VOID * cdecl Extract_Shape(VOID const *buffer, int shape)
  179. {
  180. ShapeBlock_Type *block = (ShapeBlock_Type*) buffer;
  181. int numshapes; // Number of shapes
  182. long offset; // Offset of shape data, from start of block
  183. char *bytebuf = (char*) buffer;
  184. /*
  185. ----------------------- Return if invalid argument -----------------------
  186. */
  187. if (!buffer || shape < 0 || shape >= block->NumShapes)
  188. return(NULL);
  189. offset = block->Offsets[shape];
  190. return(bytebuf + 2 + offset);
  191. } /* end of Extract_Shape */
  192. /***************************************************************************
  193. * Get_Shape_Width -- gets shape width in pixels *
  194. * *
  195. * INPUT: *
  196. * shape pointer to a shape *
  197. * *
  198. * OUTPUT: *
  199. * shape width in pixels *
  200. * *
  201. * WARNINGS: *
  202. * none *
  203. * *
  204. * HISTORY: *
  205. * 06/09/1992 JLB : Created. *
  206. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  207. * 05/25/1994 BR : Converted to 32-bit *
  208. *=========================================================================*/
  209. int Get_Shape_Width(VOID const *shape)
  210. {
  211. Shape_Type *shp = (Shape_Type *)shape;
  212. return (shp->Width);
  213. } /* end of Get_Shape_Width */
  214. /***************************************************************************
  215. * Get_Shape_Height -- gets shape height in pixels *
  216. * *
  217. * INPUT: *
  218. * shape pointer to a shape *
  219. * *
  220. * OUTPUT: *
  221. * shape height in pixels *
  222. * *
  223. * WARNINGS: *
  224. * none *
  225. * *
  226. * HISTORY: *
  227. * 06/09/1992 JLB : Created. *
  228. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  229. * 05/25/1994 BR : Converted to 32-bit *
  230. *=========================================================================*/
  231. int Get_Shape_Height(VOID const *shape)
  232. {
  233. Shape_Type *shp = (Shape_Type *)shape;
  234. return (shp->Height);
  235. } /* end of Get_Shape_Height */
  236. /***************************************************************************
  237. * Set_Shape_Height -- modifies shape's height *
  238. * *
  239. * The new height must be shorter than the original height. This effect *
  240. * chops off the lower portion of the shape, like it's sinking into the *
  241. * ground. *
  242. * *
  243. * INPUT: *
  244. * shape pointer to a shape *
  245. * newheight new shape height *
  246. * *
  247. * OUTPUT: *
  248. * old shape height *
  249. * *
  250. * WARNINGS: *
  251. * none *
  252. * *
  253. * HISTORY: *
  254. * 06/09/1992 JLB : Created. *
  255. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  256. * 05/25/1994 BR : Converted to 32-bit *
  257. *=========================================================================*/
  258. int cdecl Set_Shape_Height(VOID const *shape, WORD newheight)
  259. {
  260. Shape_Type *shp = (Shape_Type *)shape;
  261. WORD oldheight;
  262. oldheight = shp->Height;
  263. shp->Height = newheight;
  264. return(oldheight);
  265. } /* end of Set_Shape_Height */
  266. /***************************************************************************
  267. * Restore_Shape_Height -- restores a shape to its original height *
  268. * *
  269. * INPUT: *
  270. * shape pointer to a shape *
  271. * *
  272. * OUTPUT: *
  273. * old shape height *
  274. * *
  275. * WARNINGS: *
  276. * *
  277. * HISTORY: *
  278. * 06/09/1992 JLB : Created. *
  279. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  280. * 05/25/1994 BR : Converted to 32-bit *
  281. *=========================================================================*/
  282. int cdecl Restore_Shape_Height(VOID *shape)
  283. {
  284. Shape_Type *shp = (Shape_Type *)shape;
  285. WORD oldheight;
  286. oldheight = shp->Height;
  287. shp->Height = shp->OriginalHeight;
  288. return(oldheight);
  289. } /* end of Restore_Shape_Height */
  290. /***************************************************************************
  291. * Get_Shape_Original_Height -- gets shape's unmodified height *
  292. * *
  293. * INPUT: *
  294. * shape pointer to a shape *
  295. * *
  296. * OUTPUT: *
  297. * shape's unmodified height *
  298. * *
  299. * WARNINGS: *
  300. * none *
  301. * *
  302. * HISTORY: *
  303. * 06/09/1992 JLB : Created. *
  304. * 08/19/1993 SKB : Split drawshp.asm into several modules. *
  305. * 05/25/1994 BR : Converted to 32-bit *
  306. *=========================================================================*/
  307. int Get_Shape_Original_Height(VOID const *shape)
  308. {
  309. Shape_Type *shp = (Shape_Type *)shape;
  310. return (shp->OriginalHeight);
  311. } /* end of Get_Shape_Original_Height */
  312. /************************* end of getshape.cpp *****************************/