File: cf2bmp.cpp

package info (click to toggle)
crimson 0.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,968 kB
  • sloc: cpp: 21,862; ansic: 1,722; xml: 1,625; sh: 994; makefile: 277
file content (91 lines) | stat: -rw-r--r-- 2,480 bytes parent folder | download | duplicates (4)
1
2
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
/* cf2bmp -- create an image for a Crimson Fields level file
   Copyright (C) 2004-2007 Jens Granseuer

   Usage: cf2bmp <file>.lev <map>.bmp
   The unit and tile sets must be present in the working directory.

   This program 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.

   This program 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 this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <iostream>
#include <string>
using namespace std;

#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif

#include "SDL.h"

#include "mission.h"
#include "mapview.h"
#include "globals.h"

#ifdef _MSC_VER
// SDL_Main linkage destroys the command line in VS8
#undef main
#endif

int main( int argc, char *argv[] ) {
  string outmap, level;

  if ( argc != 3 ) {
    cout << "Usage: " << argv[0] << " <file>.lev <image>.bmp" << endl
         << "  --help     display this help and exit" << endl;
    return 1;
  } else {
    level = argv[1];
    outmap = argv[2];
  }

  if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    cerr << "Error: Could not init SDL. " << SDL_GetError() << endl;
    return 1;
  }
  atexit(SDL_Quit);

  Mission m;
  if ( m.Load( level.c_str() ) ) {
    cerr << "Error: Could not load level " << level << endl;
    return 1;
  }

  // create full-size bmp image
  Surface ms;
  Map &map = m.GetMap();
  const TerrainSet &tset = m.GetTerrainSet();
  Rect size( 0, 0,
       map.Width() * (tset.TileWidth() - tset.TileShiftX()) + tset.TileShiftX(),
       map.Height() * tset.TileHeight() + tset.TileShiftY() );
  if ( ms.Create( size.w, size.h, DISPLAY_BPP, 0 ) ) {
    cerr << "Error: Could not create surface" << endl;
    return 1;
  }

  MapView mv( &ms, size, MV_DISABLE_FOG|MV_DISABLE_CURSOR );
  mv.SetMap( &map );
  mv.Enable();
  mv.Draw();

  if ( SDL_SaveBMP( ms.s_surface, outmap.c_str() ) ) {
    cerr << "Error: Could not save to " << outmap << endl;
    return 1;
  }

  return 0;
}