| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 
 | // Copyright 2003 Jeremy Sawicki
//
// This file is part of OxydLib.
//
// OxydLib is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// OxydLib is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with OxydLib; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#include <stdio.h>
#include "OxydVersion.h"
#include <string>
#include "VecUtils.h"
#include "FileUtils.h"
#include "DatFile.h"
#include "Level.h"
using namespace std;
using namespace OxydLib;
void usage()
{
  printf("Usage:\n");
  printf("  printlevels [options] <datfile>\n");
  printf("\n");
  printf("Description:\n");
  printf("  The printlevels program parses the Oxyd data file specified by <datfile>,\n");
  printf("  and displays some information about each level.  The contents of the\n");
  printf("  surface, piece, and object grids are displayed, as is the table of\n");
  printf("  signals.\n");
  printf("\n");
  printf("Options:\n");
  printf("  -v1  Oxyd 1\n");
  printf("  -vm  Oxyd Magnum\n");
  printf("  -vg  Oxyd Magnum Gold\n");
  printf("  -vp  PerOxyd (default)\n");
  printf("  -ve  Oxyd Extra\n");
  printf("\n");
}
int main(int argc, char *argv[])
{
  OxydVersion ver = OxydVersion_PerOxyd;
  bool bGotDatFile = false;
  string strDatFile;
  int nArg = 1;
  while (nArg < argc) {
    string strArg(argv[nArg]);
    nArg++;
    if (strArg.compare("-v1") == 0) {
      ver = OxydVersion_Oxyd1;
    } else if (strArg.compare("-vm") == 0) {
      ver = OxydVersion_OxydMagnum;
    } else if (strArg.compare("-vg") == 0) {
      ver = OxydVersion_OxydMagnumGold;
    } else if (strArg.compare("-vp") == 0) {
      ver = OxydVersion_PerOxyd;
    } else if (strArg.compare("-ve") == 0) {
      ver = OxydVersion_OxydExtra;
    } else if (!bGotDatFile) {
      strDatFile = strArg;
      bGotDatFile = true;
    } else {
      usage();
      exit(1);
    }
  }
  if (!bGotDatFile) {
    usage();
    exit(1);
  }
  ByteVec fileData;
  bool success = readFile(strDatFile, &fileData);
  if (!success) {
    printf("Error reading DAT file.\n");
    exit(1);
  }
  DatFile datFile;
  string msg;
  success = parseDatFile(fileData, ver, &datFile, &msg);
  if (!success) {
    printf("Error parsing DAT file:\n");
    printf("%s\n", msg.c_str());
    exit(1);
  }
  for (int nLevel = 0; nLevel < 200; nLevel++) {
    printf("Level %d:\n", nLevel + 1);
    Level level;
    success = parseLevel(datFile.getLevel(nLevel), &level, &msg);
    if (!success) {
      printf("Error parsing level:\n");
      printf("%s\n", msg.c_str());
      printf("\n");
      continue;
    }
    if (level.isEmpty()) {
      printf("Level is empty.\n");
      printf("\n");
      continue;
    }
    {
      for (int gridTypeInt = GridType_First;
           gridTypeInt <= GridType_Last;
           gridTypeInt++) {
        GridType gridType = GridType(gridTypeInt);
        switch (gridType) {
        case GridType_Surfaces: printf("Surfaces:\n"); break;
        case GridType_Pieces:   printf("Pieces:\n");   break;
        case GridType_Objects:  printf("Objects:\n");  break;
        default: exit(1);
        }
        for (unsigned int y = 0; y < level.getHeight(); y++) {
          for (unsigned int x = 0; x < level.getWidth(); x++) {
            unsigned char byteVal = level.getGrid(gridType).get(x, y);
            if (x > 0) {
              printf(" ");
            }
            printf("%02x", byteVal);
          }
          printf("\n");
        }
        printf("\n");
      }
    }
    {
      printf("Signals:\n");
      set<SignalLocation> senders;
      level.getSenders(&senders);
      set<SignalLocation>::const_iterator senderIter = senders.begin();
      set<SignalLocation>::const_iterator senderEnd = senders.end();
      for (; senderIter != senderEnd; ++senderIter) {
        const SignalLocation &sender = *senderIter;
        printf("  %s (%3u, %3u)\n",
               sender.getGridType() == GridType_Pieces ? "Piece "
               : (sender.getGridType() == GridType_Surfaces ? "Surface" : "Object"),
               sender.getX(),
               sender.getY());
        int numRecipients = level.getNumRecipients(sender);
        for (int nRecipient = 0;
             nRecipient < numRecipients;
             nRecipient++) {
          const SignalLocation &recipient =
            level.getRecipient(sender, nRecipient);
          printf("   -> %s (%3u, %3u)\n",
                 recipient.getGridType() == GridType_Pieces ? "Piece "
                 : (recipient.getGridType() == GridType_Surfaces ? "Surface" : "Object"),
                 recipient.getX(),
                 recipient.getY());
        }
      }
      printf("\n");
    }
  }
  return 0;
}
 |