Advertisement
tm512

alfgen 0.0.1

Oct 15th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. // Argon Level Format Map Generator
  2.  
  3. #include <stdio.h>
  4.  
  5. #define ARG_VERSION 0x01
  6.  
  7. void alf_WriteHeader (FILE *file)
  8. {
  9. char buf [5] = {0};
  10. char *bufp = buf;
  11.  
  12. *bufp = ARG_VERSION;
  13. bufp ++;
  14. *((int*)bufp) = 0;
  15.  
  16. fwrite (buf, 1, 5, file);
  17.  
  18. return;
  19. }
  20.  
  21. int numrooms = 0;
  22. void alf_WriteRoomHeader (FILE *file, short x, short y, short flags)
  23. {
  24. char buf [6] = {0};
  25. char *bufp = buf;
  26.  
  27. *((short*)bufp) = x;
  28. *((short*)bufp) = y;
  29. *((short*)bufp) = flags;
  30.  
  31. numrooms ++;
  32. fwrite (buf, 2, 3, file);
  33.  
  34. return;
  35. }
  36.  
  37. int numblocks = 0;
  38. void alf_WriteBlock (FILE *file, char tileset)
  39. {
  40. printf ("%i", (int)tileset);
  41. numblocks ++;
  42.  
  43. if (!(numblocks % 16))
  44. printf ("\n");
  45.  
  46. fwrite (&tileset, 1, 1, file);
  47. return;
  48. }
  49.  
  50. int main (int argc, char **argv)
  51. {
  52. char *date = __DATE__;
  53. char inc;
  54. FILE *in = NULL, *out = NULL;
  55.  
  56. printf ("alf generator version 0.0.1 compiled on %s\n", date);
  57.  
  58. if (argc < 3)
  59. {
  60. printf ("usage: alfgen <input> <output>\n");
  61. return 1;
  62. }
  63.  
  64. in = fopen (argv [1], "r");
  65. out = fopen (argv [2], "w");
  66.  
  67. if (!in)
  68. {
  69. printf ("error: couldn't open input file %s\n", argv [1]);
  70. return 1;
  71. }
  72.  
  73. if (!out)
  74. {
  75. printf ("error: couldn't open output file %s\n", argv [2]);
  76. return 1;
  77. }
  78.  
  79. alf_WriteHeader (out);
  80. alf_WriteRoomHeader (out, 0, 0, 0);
  81.  
  82. while ((inc = fgetc (in)) != EOF)
  83. {
  84. if (inc == '+')
  85. alf_WriteBlock (out, 1);
  86. else if (inc == '-')
  87. alf_WriteBlock (out, 0);
  88. }
  89.  
  90. printf ("success: wrote %i rooms and %i blocks to %s\n", numrooms, numblocks, argv [2]);
  91.  
  92. return 0;
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement