File: bi2pcx2.cpp

package info (click to toggle)
asc 2.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 75,080 kB
  • ctags: 24,943
  • sloc: cpp: 155,023; sh: 8,829; ansic: 6,890; makefile: 650; perl: 138
file content (195 lines) | stat: -rw-r--r-- 5,795 bytes parent folder | download | duplicates (9)
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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
    This file is part of Advanced Strategic Command; http://www.asc-hq.de
    Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger

    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; see the file COPYING. If not, write to the 
    Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
    Boston, MA  02111-1307  USA
*/


#include "string.h"
#include "..\vesa.h"
#include "..\keybp.h"
#include "..\loadpcx.h"
#include "..\newfont.h"
#include "..\misc.h"

int background = 255;

struct tbipictparam {
   int textnum;
   struct {
     char text[40];
     int color;
   } entry[20];
} bipict[4000];


int main(int argc, char *argv[] )
{
//   keeporiginalpalette = 1;

   t_carefor_containerstream cfcst;


  int index = 0;
  int wide = 0;
  int verbosity = 0;

   for (int i = 1; i<argc; i++ ) {
      if ( argv[i][0] == '/'  ||  argv[i][0] == '-' ) {
         if ( strcmpi ( &argv[i][1], "WIDE" ) == 0 ) 
            wide = 1;
         else 
            if ( strcmpi ( &argv[i][1], "INDEX" ) == 0 )
               index = 1;
            else
               if ( strcmpi ( &argv[i][1], "verbosity" ) == 0 )
                  verbosity = 1;
               else
                 if ( ( strcmpi ( &argv[i][1], "?" ) == 0 ) || ( strcmpi ( &argv[i][1], "h" ) == 0 ) ){
                    printf( " Parameters: \n"
                            "     /h          this page\n"
                            "     /index      output index\n"
                            "     /verbosity  increase verbosity level\n"
                            "     /wide       use wide output ( 10 columns ) \n\n"     );
                    return (0);
   
                 } else {
                     printf ( "\nInvalid command line parameter: %s \n", argv[i] );
                     return (1);
                 }
       } else {
           printf ( "\nInvalid command line parameter: %s \n", argv[i] );
           return (1);
       }
   } /* endfor */

   initsvga(0x101);
   loadpcxxy ("bi2\\dump0000.pcx", 1, 0, 0 );
   closesvga();
   settextmode(3);

      int ys;
      int colnum;
      if ( wide ) {
         ys = 1600;
         colnum = 40;
      } else {
         ys = 400;
         colnum = 10;
      }
   
      printf("\nallocating buffer \n" ) ;
      fflush ( stdout );
   
      tvirtualdisplay vdp ( ys, 30000 / ( wide + 1 ), 255 );
   
      int colxl[] = {0, black, blue, green, red };
   
      int x0 = 30;
      int xd = ( agmp->resolutionx - 2 * x0 ) / colnum ;
   
   
      int y0 = 10;
      int yd = fieldsizey/2 + 5;
   
      char* name = "monogui.fnt";
      pfont fnt;
      {
         tnfilestream stream ( name, 1 );
         fnt = loadfont  ( &stream );
      }
      if ( !fnt ) {
         printf("error loading file %s \n", name );
         return 1;
      }


      activefontsettings.font = fnt; 
      activefontsettings.color = black; 
      activefontsettings.background = 255; 
      activefontsettings.length = xd;
      activefontsettings.justify = lefttext; 
      activefontsettings.height = 0; 
   
   
      int yp = y0;
      int lastlinenum = 0;
   
      if ( wide )
         line ( agmp->resolutionx / 2 - 3, 0, agmp->resolutionx / 2 - 3, agmp->resolutiony -1, black );
   
      loadbi3graphics();

      printf("Generating image: \n" ) ;
      fflush ( stdout );
   
      for ( i = 0; i < bi3graphnum; i++ ) {
         void* v;
         loadbi3pict ( i, &v );
         if ( !(i % colnum) ) {
            if ( i ) {
              if ( yd > (activefontsettings.font->height + 2 )* lastlinenum ) 
                 yp += yd;
              else
                 yp += (activefontsettings.font->height + 2 ) * (lastlinenum + 1);
            }
            lastlinenum = 0;
            activefontsettings.color = black; 
            showtext2 ( strrr ( i ), 1, yp + ( fieldsizey/2 - activefontsettings.font->height) / 2 );
   
            if ( verbosity )
               printf ( "line %d\n", i / colnum );
            else
               printf(".");
            fflush ( stdout );
         }
   
         if ( v ) {
            putimage ( x0 + (i % colnum) * xd, yp, v );
            for ( int j = 0; j < bipict[i].textnum; j++ ) {
               activefontsettings.color = colxl[bipict[i].entry[j].color]; 
               showtext2 ( bipict[i].entry[j].text, x0 + (i % colnum) * xd + fieldsizex/2 + 5 , yp + j * (activefontsettings.font->height + 2 ));
   
               if ( lastlinenum < j+1 )
                  lastlinenum = j+1;
            }
   
   
            delete v;
   
         }
      }
   
      printf ( "\nwriting pcx\n", i / colnum );
      char* outputfilename = "biograph.pcx";
      writepcx ( outputfilename, 0, 0, agmp->resolutionx-1, yp + fieldsizey/2 + (activefontsettings.font->height + 2 ) * (lastlinenum + 1), *activepalette256 );
      printf ( "%s written\n", outputfilename );
   
      if ( index ) {
         tnfilestream strm ( "bi_index.raw", 1 );
         int w;
         void* p;
         strm.readrlepict ( &p, false, &w );
         putimage ( 0, 0, p );
         char* outputfilename2 = "INDEX.PCX";
         writepcx ( outputfilename2, 0, 0, 639, 479, pal );
         printf ( "\nIndex file %s written\n", outputfilename2 );
      }

   return 0;

}