LEVELS.CPP 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "debug4g.h"
  5. #include "inifile.h"
  6. #include "levels.h"
  7. #include "globals.h"
  8. #include "resource.h"
  9. #include "misc.h"
  10. #include "screen.h"
  11. #include <memcheck.h>
  12. /***********************************************************************
  13. *
  14. **********************************************************************/
  15. char gLevelName[_MAX_PATH];
  16. int gEpisodeId = kMinEpisode;
  17. int gMapId = kMinMap;
  18. int gEndingA, gEndingB;
  19. int gEndLevelFlag = 0;
  20. char gLevelAuthor[128];
  21. char gLevelDescription[128];
  22. char gLevelSong[128];
  23. char *gLevelMessage[64];
  24. LIGHTNING gLightningInfo[ kMaxLightning ];
  25. /***********************************************************************
  26. * Process command line arguments
  27. **********************************************************************/
  28. void levelGetName(int episodeId, int mapId)
  29. {
  30. char zEpisode[13], zMap[13];
  31. sprintf(zEpisode, "EPISODE%1d.DEF", episodeId);
  32. IniFile EpisodeINI(zEpisode);
  33. sprintf( zMap, "Map%d", mapId );
  34. char *key = EpisodeINI.GetKeyString(NULL, zMap, NULL);
  35. if (key == NULL)
  36. {
  37. dprintf("%s not found in level definition file\n", zMap);
  38. return;
  39. }
  40. dprintf("%s=%s\n", zMap, key);
  41. sscanf(key, "%[^, ],%i,%i", gLevelName, &gEndingA, &gEndingB);
  42. }
  43. void levelLoadDef( void )
  44. {
  45. char defName[13];
  46. strcpy(defName, gLevelName);
  47. ChangeExtension(defName, ".DEF");
  48. IniFile levelDef(defName);
  49. strcpy(gLevelAuthor, levelDef.GetKeyString(NULL, "Author", ""));
  50. strcpy(gLevelDescription, levelDef.GetKeyString(NULL, "Description", ""));
  51. strcpy(gLevelSong, levelDef.GetKeyString(NULL, "Song", ""));
  52. gFogMode = levelDef.GetKeyBool(NULL, "Fog", FALSE);
  53. // load the level messages
  54. for (int i = 0; i < 64; i++)
  55. {
  56. if ( gLevelMessage[i] != NULL )
  57. {
  58. Resource::Free(gLevelMessage[i]);
  59. gLevelMessage[i] = NULL;
  60. }
  61. char messageKey[10];
  62. sprintf(messageKey, "Message%d", i);
  63. char *msg = levelDef.GetKeyString(NULL, messageKey, NULL);
  64. if (msg != NULL)
  65. {
  66. gLevelMessage[i] = (char *)Resource::Alloc(strlen(msg));
  67. strcpy(gLevelMessage[i], msg);
  68. }
  69. }
  70. // load the level lightning definitions
  71. for (i = 0; i < kMaxLightning; i++)
  72. {
  73. // preinitialize lightning
  74. gLightningInfo[i].slot = -1;
  75. gLightningInfo[i].offset = -1;
  76. char forkKey[16];
  77. sprintf(forkKey, "Lightning%d", i);
  78. char *msg = levelDef.GetKeyString(NULL, forkKey, NULL);
  79. if (msg != NULL)
  80. sscanf(msg, "%i,%i", &gLightningInfo[i].slot, &gLightningInfo[i].offset);
  81. }
  82. }