GETSHAPE.CPP 18 KB

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