BSTUBIO.CPP 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. #include "db.h"
  6. #include "engine.h"
  7. #include "error.h"
  8. #include <memcheck.h>
  9. /***********************************************************************
  10. * ImportBuildMap()
  11. *
  12. **********************************************************************/
  13. int ImportBuildMap(
  14. char *filename,
  15. long *daposx,
  16. long *daposy,
  17. long *daposz,
  18. short *daang,
  19. short *dacursectnum )
  20. {
  21. int fil;
  22. short int i, numsprites;
  23. long mapversion;
  24. if ((fil = open(filename,O_BINARY|O_RDWR,S_IREAD)) == -1)
  25. {
  26. mapversion = 6L;
  27. return -1;
  28. }
  29. read(fil,&mapversion,4);
  30. if (mapversion != 6L)
  31. return -1;
  32. *gMapName = '\0';
  33. *gMapAuthor = '\0';
  34. gSkyCount = 1;
  35. pskyoff[0] = 0;
  36. dbInit(); // calls initspritelists() too!
  37. memset(show2dsprite, 0, sizeof(show2dsprite));
  38. memset(show2dwall, 0, sizeof(show2dwall));
  39. read(fil,daposx,4);
  40. read(fil,daposy,4);
  41. read(fil,daposz,4);
  42. read(fil,daang,2);
  43. read(fil,dacursectnum,2);
  44. read(fil,&numsectors,2);
  45. read(fil,sector,sizeof(SECTOR)*numsectors);
  46. read(fil,&numwalls,2);
  47. read(fil,wall,sizeof(WALL)*numwalls);
  48. read(fil,&numsprites,2);
  49. read(fil,sprite,sizeof(SPRITE)*numsprites);
  50. for( i=0; i<numsprites; i++)
  51. insertsprite(sprite[i].sectnum,sprite[i].statnum);
  52. //Must be after loading sectors, etc!
  53. updatesector(*daposx,*daposy,dacursectnum);
  54. close(fil);
  55. highlightcnt = -1;
  56. highlightsectorcnt = -1;
  57. precache();
  58. printmessage16("Map imported successfully.");
  59. updatenumsprites();
  60. startposx = posx; //this is same
  61. startposy = posy;
  62. startposz = posz;
  63. startang = ang;
  64. startsectnum = cursectnum;
  65. return 0;
  66. }
  67. /***********************************************************************
  68. * ExportBuildMap()
  69. *
  70. **********************************************************************/
  71. int ExportBuildMap(
  72. char *filename,
  73. long *daposx,
  74. long *daposy,
  75. long *daposz,
  76. short *daang,
  77. short *dacursectnum )
  78. {
  79. int fil;
  80. short int i, j, numsprites;
  81. long mapversion = 6L;
  82. if ((fil = open(filename,O_BINARY|O_TRUNC|O_CREAT|O_WRONLY,S_IWRITE)) == -1)
  83. return -1;
  84. write(fil,&mapversion,4);
  85. write(fil,daposx,4);
  86. write(fil,daposy,4);
  87. write(fil,daposz,4);
  88. write(fil,daang,2);
  89. write(fil,dacursectnum,2);
  90. write(fil,&numsectors,2);
  91. write(fil,sector,sizeof(SECTOR)*numsectors);
  92. write(fil,&numwalls,2);
  93. write(fil,wall,sizeof(WALL)*numwalls);
  94. numsprites = 0;
  95. for(j=0;j<kMaxStatus;j++)
  96. {
  97. i = headspritestat[j];
  98. while (i != -1)
  99. {
  100. numsprites++;
  101. i = nextspritestat[i];
  102. }
  103. }
  104. write(fil,&numsprites,2);
  105. for(j=0;j<kMaxStatus;j++)
  106. {
  107. i = headspritestat[j];
  108. while (i != -1)
  109. {
  110. write(fil,&sprite[i],sizeof(SPRITE));
  111. i = nextspritestat[i];
  112. }
  113. }
  114. close(fil);
  115. return 0;
  116. }
  117. #if 0
  118. /***************************************************************************
  119. KEN'S TAG DEFINITIONS: (Please define your own tags for your games)
  120. sector[?].lotag = 0 Normal sector
  121. sector[?].lotag = 1 If you are on a sector with this tag, then all sectors
  122. with same hi tag as this are operated. Once.
  123. sector[?].lotag = 2 Same as sector[?].tag = 1 but this is retriggable.
  124. sector[?].lotag = 3 A really stupid sector that really does nothing now.
  125. sector[?].lotag = 4 A sector where you are put closer to the floor
  126. (such as the slime in DOOM1.DAT)
  127. sector[?].lotag = 5 A really stupid sector that really does nothing now.
  128. sector[?].lotag = 6 A normal door - instead of pressing D, you tag the
  129. sector with a 6. The reason I make you edit doors
  130. this way is so that can program the doors
  131. yourself.
  132. sector[?].lotag = 7 A door the goes down to open.
  133. sector[?].lotag = 8 A door that opens horizontally in the middle.
  134. sector[?].lotag = 9 A sliding door that opens vertically in the middle.
  135. -Example of the advantages of not using BSP tree.
  136. sector[?].lotag = 10 A warping sector with floor and walls that shade.
  137. sector[?].lotag = 11 A sector with all walls that do X-panning.
  138. sector[?].lotag = 12 A sector with walls using the dragging function.
  139. sector[?].lotag = 13 A sector with some swinging doors in it.
  140. sector[?].lotag = 14 A revolving door sector.
  141. sector[?].lotag = 15 A subway track.
  142. sector[?].lotag = 16 A true double-sliding door.
  143. sector[?].lotag = 17 A true double-sliding door for subways only.
  144. wall[?].lotag = 0 Normal wall
  145. wall[?].lotag = 1 Y-panning wall
  146. wall[?].lotag = 2 Switch - If you flip it, then all sectors with same hi
  147. tag as this are operated.
  148. wall[?].lotag = 3 Marked wall to detemine starting dir. (sector tag 12)
  149. wall[?].lotag = 4 Mark on the shorter wall closest to the pivot point
  150. of a swinging door. (sector tag 13)
  151. wall[?].lotag = 5 Mark where a subway should stop. (sector tag 15)
  152. wall[?].lotag = 6 Mark for true double-sliding doors (sector tag 16)
  153. wall[?].lotag = 7 Water fountain
  154. sprite[?].lotag = 0 Normal sprite
  155. sprite[?].lotag = 1 If you press space bar on an AL, and the AL is tagged
  156. with a 1, he will turn evil.
  157. sprite[?].lotag = 2 When this sprite is operated, a bomb is shot at its
  158. position.
  159. sprite[?].lotag = 3 Rotating sprite.
  160. sprite[?].lotag = 4 Sprite switch.
  161. sprite[?].lotag = 5 Basketball hoop score.
  162. **************************************************************************/
  163. /***********************************************************************
  164. * ConvertKenTriggers()
  165. *
  166. * Called in loadboard and saveboard. Converts Ken's triggers
  167. * to XSECTOR data, leaving the sector lotag and hitag intact.
  168. **********************************************************************/
  169. void ConvertKenTriggers( void )
  170. {
  171. int nSector, nXSector;
  172. for ( nSector = 0; nSector < numsectors; nSector++ )
  173. {
  174. switch (sector[nSector].lotag)
  175. {
  176. case 1: // kSectorTriggerOnEnterOnce
  177. case 2: // kSectorTriggerOnEnter
  178. case 4: // kSectorWadeWater
  179. case 6: // kSectorRaiseDoor
  180. case 7: // kSectorLowerDoor
  181. case 8: // kSectorHorizontalDoors
  182. case 9: // kSectorVerticalDoors
  183. case 10: // kSectorTeleport
  184. case 11: // kSectorXPanWalls
  185. case 12: // kSectorDragWalls
  186. case 13: // kSectorContainsSwingingDoors
  187. case 14: // kSectorRevolveWalls
  188. case 16: // kSectorPeggedVerticalDoors
  189. case 100: // kSectorMovesUp
  190. case 101: // kSectorMovesDown
  191. break;
  192. default:
  193. break;
  194. }
  195. // get or create an extra structure
  196. if ( sector[nSector].extra > 0 ) {
  197. nXSector = sector[nSector].extra;
  198. dassert(nXSector < kMaxXSectors);
  199. } else {
  200. nXSector = GetXSector(nSector);
  201. dassert(nXSector < kMaxXSectors);
  202. }
  203. // fill the extra here...
  204. }
  205. }
  206. #endif