Advanced Strategic Command
edgen.cpp
Go to the documentation of this file.
1 
5 /*
6  This file is part of Advanced Strategic Command; http://www.asc-hq.de
7  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; see the file COPYING. If not, write to the
21  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  Boston, MA 02111-1307 USA
23 */
24 
25 #include "global.h"
26 #include "edmisc.h"
27 #include "edgen.h"
28 #include "vehicletype.h"
29 #include "itemrepository.h"
30 #include "paradialog.h"
31 #include "spfst-legacy.h"
32 
33 #define layercount 5
34 #define centerlayer 65000
35 #define maxoverwrite 5
36 
37  class tmapgenerator : public tdialogbox {
38  public :
39  int action;
40  void init(void);
41  void showmap(void);
42  void generatefinishmap(void); // Bodensch�tze werden nicht draufmontiert, damit keine Farbverf�lschung
43  void montlayer(int layer);
44  void showmontlayer( int sx, int sy, int barsize);
45  void setpfield(int number);
46  void setmaterial(int number);
47  void setfuel(int number);
48  void resetmapfield(void);
49  void addcoast(void);
50  void setmap(void);
51  Uint8 checkland(int x, int y);
52  virtual void run(void);
53  virtual void buttonpressed(int id);
54  protected :
60  int whereland;
67  };
68 
69 const char* clayer[layercount] = {"Land", "Forest", "Desert","Material","Fuel"};
70 
71 
73 {
74  int w;
75  char s1[100],s2[100];
76 
78  action = 0;
79  title = "Map generator";
80  x1 = 10;
81  xsize = 620;
82  y1 = 10;
83  ysize = 460;
84 
85  w = (xsize - 160) / 2;
87 
88  for (int i=0;i < layercount ;i++ ) initialized[i] =false;
89 
90  plasma.maxx = actmap->xsize * 2;
92  flip = plasma.flip;
93  res = 10;
94  if (res > plasma.maxx / 5) res = plasma.maxx / 5;
95  pres = 300;
96  tileval = 0;
97  actlayer = layer = 0;
98 
99 
100  int xmax = 430 / plasma.maxx;
101  int ymax = 340 / plasma.maxy;
102 
103  if (xmax > ymax ) maxbarsize = ymax;
104  else maxbarsize = xmax;
105 
107 
108  constructionlayer = new Uint8[plasma.maxx * plasma.maxy ]; // =blockcount
109 
110  addbutton("",480,80,510,100,0,1,7,true);
111  addkey(7,ct_down);
112  addbutton("",530,80,560,100,0,1,8,true);
113  addkey(8,ct_up);
114 
115  addbutton("~G~enerate new",460,115,580,135,0,1,1,true);
116 
117  addbutton("~R~esolution",460,155,580,175,2,1,3,true);
118  addeingabe(3,&res,1,plasma.maxx / 5);
119 
120  addbutton("~P~recission",460,195,580,215,2,1,4,true);
121  addeingabe(4,&pres,0,30000);
122 
123  addbutton("~F~lip map",480,225,580,240,3,1,9,true);
124  addeingabe(9,&flip,0,lightgray);
125 
126  addbutton("",460,295,580,315,2,1,2,true);
127  addeingabe(2,&tileval,0,pres);
128 
129  addbutton("-",480,330,510,350,0,1,5,true);
130  addkey(5,ct_minus);
131  addbutton("+",530,330,560,350,0,1,6,true);
132  addkey(6,ct_plus);
133 
134  addbutton("",480,370,510,390,0,1,11,true);
135  addkey(11,ct_left);
136  addbutton("",530,370,560,390,0,1,12,true);
137  addkey(12,ct_right);
138 
139  correctvalues = true;
140  addbutton("Co~r~rect",520,410,600,420,3,1,50,true);
142 
143  calculatevalues = true;
144  addbutton("Ca~l~culate",520,430,600,440,3,1,51,true);
146 
147  if ( maxbarsize >=1 ) addbutton("1",345,395,360,410,0,1,13,true);
148  addkey(13,ct_1);
149  if ( maxbarsize >=2 ) addbutton("2",365,395,380,410,0,1,14,true);
150  addkey(14,ct_2);
151  if ( maxbarsize >=3 ) addbutton("3",385,395,400,410,0,1,15,true);
152  addkey(15,ct_3);
153  if ( maxbarsize >=4 ) addbutton("4",405,395,420,410,0,1,16,true);
154  addkey(16,ct_4);
155  if ( maxbarsize >=5 ) addbutton("5",425,395,440,410,0,1,17,true);
156  addkey(17,ct_5);
157 
158  addbutton ("~x~sym", 455,20,500,30, 3, 0, 31, true );
159  addeingabe ( 31, &plasma.xsymm, 0, lightgray );
160 
161  addbutton ("~y~sym", 510,20,560,30, 3, 0, 32, true );
162  addeingabe ( 32, &plasma.ysymm, 0, lightgray );
163 
164  addbutton("~A~ccept Map",20,ysize - 40,20 + w,ysize - 10,0,1,19,true);
165  addbutton("~C~ancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,20,true);
166 
167  buildgraphics();
168 
174 
175  showtext2("Layer",x1+460,y1+52);
176  rahmen(true,x1 + 500,y1 + 50,x1 + 580,y1 + 70);
177  showtext2(clayer[layer],x1+505,y1+52);
178 
179  showtext2("Limit",x1+460,y1+267);
180  rahmen(true,x1 + 500,y1 + 265,x1 + 580,y1 + 285);
181 
182  strcpy(s1,"XSize : ");
183  strcpy(s2,"YSize : ");
184  showtext2(strcat(s1,strrr(plasma.maxx)),x1+10,y1+10);
185  showtext2(strcat(s2,strrr(plasma.maxy)),x1+120,y1+10);
186 
187  /*
188  putspriteimage(x1 + 487,y1 + 83,icons.pfeil2[6]);
189  putspriteimage(x1 + 537,y1 + 83,icons.pfeil2[2]);
190 
191  putspriteimage(x1 + 487,y1 + 373,icons.pfeil2[6]);
192  putspriteimage(x1 + 537,y1 + 373,icons.pfeil2[2]);
193  */
194 
195  rahmen(true,x1 + 450,y1 + 40,x1 + 590,y1 + 400);
196  rahmen(true,x1 + 10,y1 + 40,x1 + 440,y1 + 390);
197 
198  //activefontsettings.length = 170;
199  //showtext2("Press F1 for Help !",200,190);
200 
201  //showmemory();
202 
203  mousevisible(true);
204 }
205 
206 
208 {
209  int i,j;
210  Uint8 found;
211 
212  if ( overwritecolorcount == 0 ){
213  for (i=0;i<plasma.blockcount;i++ ) {
214  found = false;
215  j=0;
216  do {
217  if (mblocks[layer]->mempointer[i] <= mblocks[layer]->tileval[j] ) {
218  if ( mblocks[layer]->color[j] != ctransparent ) constructionlayer[i] = mblocks[layer]->color[j];
219  found = true;
220  }
221  else j++;
222  } while ( ( found == false ) && (j < mblocks[layer]->tilevalcount ) ); /* enddo */
223  if ( (j == mblocks[layer]->tilevalcount ) && ( mblocks[layer]->color[int(mblocks[layer]->tilevalcount)] != ctransparent ) )
224  constructionlayer[i] = mblocks[layer]->color[int(mblocks[layer]->tilevalcount)];
225  } /* endfor */
226  } else {
227  for (i=0;i<plasma.blockcount;i++ ) {
228  for (int k=0;k<overwritecolorcount;k++ ) {
229  if (constructionlayer[i] == overwritecolor[k]) {
230  found = false;
231  j=0;
232  do {
233  if (mblocks[layer]->mempointer[i] <= mblocks[layer]->tileval[j] ) {
235  found = true;
236  }
237  else j++;
238  } while ( ( found == false ) && (j < mblocks[layer]->tilevalcount ) ); /* enddo */
239  if (j == mblocks[layer]->tilevalcount )
240  constructionlayer[i] = mblocks[layer]->color[int(mblocks[layer]->tilevalcount)];
241  }
242  } /* endfor */
243  } /* endfor */
244  } /* endif */
245 }
246 
247 /*void setmem(word x, word y,word color)
248 {
249  [ x + (y * maxx ) ] = color;
250 }
251 
252 void membar(word x1 ,word y1 ,word x2 ,word y2, word color )
253 { word exc;
254  if (x1 >x2) {
255  exc = x1;
256  x1 = x2;
257  x2 = exc;
258  }
259 
260  if (y1 >y2) {
261  exc = y1 ;
262  y1 = y2 ;
263  y2 = exc ;
264  }
265 
266  for (int j=y1;j<=y2;j++ ) {
267  for (int i=x1;i<=x2;i++) {
268  //memblock->mempointer[ i + (j * maxx ) ] = color;
269  setmem(i,j,color);
270  }
271  }
272 }*/
273 
274 
275 void tmapgenerator::showmontlayer(int sx, int sy, int barsize)
276 {
277  int i;
278 
279  int prevx,prevy;
280 
281  //prevx = x1 + 15;
282  //prevy = y1 + 45;
283 
284  prevx = x1 + 15 + (430 - plasma.maxx * barsize ) / 2;
285  prevy = y1 + 45 + (340 - plasma.maxy * barsize ) / 2;
286 
287  if (sx == centerlayer) sx = prevx;
288  if (sy == centerlayer) sy = prevy;
289 
290  /*byte *constlayer2 = new ( byte[plasma.maxx * plasma.maxy + 4]); // =blockcount + 2 * word f�r x/y-size
291  (word *) constlayer2[0] = plasma.maxx;
292  (word *) constlayer2[1] = plasma.maxy;
293 
294  if (flip == true) {
295  for (i=plasma.blockcount-1;i>=0 ;i-- ) {
296  if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
297  else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
298  x += barsize;
299  if (x >= sx + (plasma.maxx) * barsize ) {
300  x = sx;
301  y += barsize;
302  }
303  }
304  } else {
305  for (i=0;i<plasma.blockcount;i++ ) {
306  if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
307  else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
308  x += barsize;
309  if (x >= sx + (plasma.maxx) * barsize ) {
310  x = sx;
311  y += barsize;
312  }
313  }
314  } */
315 
316 
317  int x,y;
318 
319  x = sx;
320  y = sy;
321 
322  if (flip == true) {
323  for (i=plasma.blockcount-1;i>=0 ;i-- ) {
324  if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
325  else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
326  x += barsize;
327  if (x >= sx + (plasma.maxx) * barsize ) {
328  x = sx;
329  y += barsize;
330  }
331  }
332  } else {
333  for (i=0;i<plasma.blockcount;i++ ) {
334  if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
335  else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
336  x += barsize;
337  if (x >= sx + (plasma.maxx) * barsize ) {
338  x = sx;
339  y += barsize;
340  }
341  }
342  }
343 }
344 
346 { // layers eintragen, die terrain beeinflussen !
348  if ( (showland == true ) && (initialized[0] == true ) ) montlayer(0);
350 
354  if ( (showforest == true ) && (initialized[1] == true ) ) montlayer(1);
355 
359  if ( (showdesert == true ) && (initialized[2] == true ) ) montlayer(2);
360 }
361 
362 // Karte wird aufgrund von Farben �bernommen !!!
363 // Wenn bodensch�tze in der fertigen karte eingezeichnet werden, dann gibt das Fehler,
364 // weil dann die Farben f�r die terrain nicht mehr stimmen !!!
365 
366 
367 
369 { // layers, die den bodentyp nicht beeinflussen
371 
373  if ( (showmaterial == true ) && (initialized[3] == true ) ) montlayer(3);
374 
376  if ( (showfuel == true ) && (initialized[4] == true ) ) montlayer(4);
377 
379 }
380 
381 Uint8 tmapgenerator::checkland(int x, int y)
382 {
383  if ( ( getfield(x,y)->typ->art & getTerrainBitType(cbwater) ).none() )
384  return true;
385  else
386  return false;
387 }
388 
390 {
391  MapField* pf;
392  const int id[2]={42,83};
393 
394  for (int i=0;i<2;i++ ) {
395  if (id[i] != 0 ) {
396  btyp[i] = terrainTypeRepository.getObject_byID(id[i]);
397  if (btyp[i] == NULL) btyp[i] = terrainTypeRepository.getObject_byPos(0);
398  }
399  } /* endfor */
400 
401 
402 
403  for (int y=0;y<actmap->ysize ;y++ ) {
404  for (int x=0;x<actmap->xsize ;x++) {
405  pf = getfield(x,y);
406  whereland = 0;
407  if ( checkland(x,y) == false ){
408  if ( (x >1 ) && (y >1 ) && (y < actmap->ysize-2 ) && ( x < actmap->xsize -2) ){ // nicht am Rand
409  if ( checkland(x+1, y) ) whereland |= 4; // 2
410  if ( checkland(x-1, y) ) whereland |= 64; // 6
411  if ( checkland(x, y+2) ) whereland |= 16; // 4
412  if ( checkland(x, y-2) ) whereland |= 1; // 0
413  if (y & 1) {
414  if ( checkland(x-1, y-1) ) whereland |= 128; // 7
415  if ( checkland(x, y-1) ) whereland |= 2; // 1
416  if ( checkland(x, y+1) ) whereland |= 8; // 3
417  if ( checkland(x-1, y+1) ) whereland |= 32; // 5
418  } else {
419  if ( checkland(x, y-1) ) whereland |= 128; // 7
420  if ( checkland(x+1,y-1) ) whereland |= 2; // 1
421  if ( checkland(x+1, y+1) ) whereland |= 8; // 3
422  if ( checkland(x, y+1) ) whereland |= 32; // 5
423  } /* endif */
424  if (whereland & 1) {
425  pf->typ = btyp[0]->weather[0];
426  // pf->direction = 0;
427  }
428  if (whereland & 2) {
429  pf->typ = btyp[1]->weather[0];
430  // pf->direction = 0;
431  }
432  if (whereland & 4) {
433  pf->typ = btyp[0]->weather[0];
434  // pf->direction = 1;
435  }
436  if (whereland & 8) {
437  pf->typ = btyp[1]->weather[0];
438  // pf->direction = 1;
439  }
440  if (whereland & 16) {
441  pf->typ = btyp[0]->weather[0];
442  // pf->direction = 2;
443  }
444  if (whereland & 32) {
445  pf->typ = btyp[1]->weather[0];
446  // pf->direction = 2;
447  }
448  if (whereland & 64) {
449  pf->typ = btyp[0]->weather[0];
450  // pf->direction = 3;
451  }
452  if (whereland & 128) {
453  pf->typ = btyp[1]->weather[0];
454  // pf->direction = 3;
455  }
456  }
457  } /* endfor */
458  } /* endfor */
459  } /* endfor */
460 }
461 
462 void tmapgenerator::setpfield(int number)
463 {
464  switch ( constructionlayer[ number ] ) {
465  case cwater : pf->typ = btyp[0]->weather[0];
466  break;
467  case cland : pf->typ = btyp[1]->weather[0];
468  break;
469  case cmount : pf->typ = btyp[2]->weather[0];
470  break;
471  case cforest : pf->typ = btyp[3]->weather[0];
472  break;
473  case cdesert : pf->typ = btyp[4]->weather[0];
474  break;
475  case cshallowwater : pf->typ = btyp[5]->weather[0];
476  break;
477  case cdeepwater : pf->typ = btyp[6]->weather[0];
478  break;
479  case cverydeepwater : pf->typ = btyp[7]->weather[0];
480  break;
481  default: pf->typ = btyp[1]->weather[0];
482  break;
483  } /* endswitch */
484 }
485 
486 int matdiv[3];
487 int fueldiv[3];
488 
489 #define enhance 1000
490 
492 {
493  for (int i =mblocks[clmaterial]->tilevalcount-1;i >=0 ;i-- ) {
494  if (mblocks[clmaterial]->mempointer[number] > mblocks[clmaterial]->tileval[i] ) {
495  int test = ( ( (mblocks[clmaterial]->mempointer[number] - mblocks[clmaterial]->tileval[i] ) * matdiv[i] / enhance ) + (i * 80)) * 14 / 10;
496  if ( test > 255 ) pf->material = 255;
497  else pf->material = test;
498  return;// Korrektur um x 1,4 => *14 / 10
499  }
500  } /* endfor */
501 }
502 
503 void tmapgenerator::setfuel(int number)
504 {
505  for (int i =mblocks[clfuel]->tilevalcount-1;i >=0 ;i-- ) {
506  if (mblocks[clfuel]->mempointer[number] > mblocks[clfuel]->tileval[i] ){
507  int test = ( ( (mblocks[clfuel]->mempointer[number] - mblocks[clfuel]->tileval[i] ) * fueldiv[i] / enhance ) + (i * 80) ) * 14 / 10;
508  if ( test>255 ) pf->fuel =255;
509  else pf->fuel = test;
510  return;// Korrektur um x 1,4 => *14 / 10
511  }
512  } /* endfor */
513 }
514 
515 
516 int terrain_object_ids[numofbdts][2][2] = {{{ 299, -1 }, { 307, -1 }}, // water
517  {{ 28 , -1 }, { 38 , -1 }}, // land
518  {{ 30 , -1 }, { 40 , -1 }}, // mountain
519  {{ 30 , -1 }, { 40 , -1 }}, // forest
520  {{ 34 , -1 }, { 35 , -1 }}, // desert
521  {{ 299, -1 }, { 307, -1 }}, // shallow water
522  {{ 301, -1 }, { 308, -1 }}, // deep water
523  {{ 302, -1 }, { 309, -1 }}, // very deep water
524  {{ 30 , -1 }, { 40 , -1 }}, // ??
525  {{ 30 , -1 }, { 40 , -1 }}, // ??
526  {{ 30 , -1 }, { 40 , -1 }}, // ??
527  {{ 30 , -1 }, { 40 , -1 }}}; // ??
528 
530 {
531  // const int id[numofbdts]={60,18,82,20,100,61,63,71,0,0,0};
532  int i,j;
533 
535 
536  int set = 2 - choice_dlg("Choose terrain set","dark","light") ;
537  for (i=0;i<numofbdts ;i++ ) {
538  btyp[i] = terrainTypeRepository.getObject_byID( terrain_object_ids[i][set][0] );
539  if ( !btyp[i] )
540  btyp[i] = terrainTypeRepository.getObject_byPos(0);
541  }
542 
543  if (initialized[clmaterial] == true ) {
544  matdiv[0] = 81 * enhance / ( mblocks[clmaterial]->tileval[1] -mblocks[clmaterial]->tileval[0] +1 ) ;
545  matdiv[1] = 80 * enhance / ( mblocks[clmaterial]->tileval[2] - mblocks[clmaterial]->tileval[1] +1 );
546  matdiv[2] = 95 * enhance / ( mblocks[clmaterial]->actpres - mblocks[clmaterial]->tileval[1] +1);
547  } // +1 damit keine 0 vorkommen kann
548 
549  if (initialized[clfuel] == true ) {
550  fueldiv[0] = 81 * enhance / ( mblocks[clfuel]->tileval[1] -mblocks[clfuel]->tileval[0] +1);
551  fueldiv[1] = 80 * enhance / ( mblocks[clfuel]->tileval[2] - mblocks[clfuel]->tileval[1] +1);
552  fueldiv[2] = 95 * enhance / ( mblocks[clfuel]->actpres - mblocks[clfuel]->tileval[1] +1);
553  }
554 
555  if ( ( actmap->xsize * 2 == plasma.maxx ) && (actmap->ysize == plasma.maxy ) ){
556  mapsaved = false;
557  if (flip == true) {
558  for (i=0;i< ( plasma.maxx / 2 ) ;i++ ) {
559  for (j=0;j<plasma.maxy;j++ ) {
560  pf = &actmap->field[ ( plasma.maxx / 2 - i - 1 ) + ( ( plasma.maxy - j -1) * plasma.maxx / 2 ) ];
561  int plasmalayernr = ( i * 2 + ( j & 1 ) ) + ( j * plasma.maxx );
562  setpfield ( plasmalayernr ) ;
563  pf->setparams();
564  if (initialized[clmaterial] == true ) setmaterial ( plasmalayernr );
565  if (initialized[clfuel] ==true ) setfuel ( plasmalayernr );
566  if ( pf->vehicle )
567  if ( terrainaccessible(pf,pf->vehicle) == false ) {
568  delete pf->vehicle;
569  pf->vehicle = NULL;
570  }
571  } /* endfor */
572  } /* endfor */
573  } else {
574  for (i=0;i< ( plasma.maxx / 2 ) ;i++ ) {
575  for (j=0;j<plasma.maxy;j++ ) {
576  pf = &actmap->field[i + ( j * plasma.maxx / 2 ) ];
577  int plasmalayernr = ( i * 2 + ( j & 1 ) ) + ( j * plasma.maxx );
578  setpfield ( plasmalayernr ) ;
579  pf->setparams();
580  if (initialized[clmaterial] == true ) setmaterial ( plasmalayernr );
581  if (initialized[clfuel] ==true ) setfuel ( plasmalayernr );
582  if ( pf->vehicle )
583  if ( terrainaccessible(pf,pf->vehicle) == false ) {
584  delete pf->vehicle;
585  pf->vehicle = NULL;
586  }
587  } /* endfor */
588  } /* endfor */
589  } /* endif */
590  }/* else {
591  displaymessage2("Map genaration failure !!! Sizes do not match !");
592  r_key();
593  removemessage();
594  }*/
595 
596  //addcoast();
597 }
598 
600 {
601  bar(x1 + 12,y1 + 42,x1 + 438,y1 + 388,lightgray);
602 }
603 
605 {
606  do {
607  tdialogbox::run();
608  if (taste == ct_f1) help(1010);
609  } while (!((taste == ct_esc) || (action >= 2)));
610  if (action == 2) setmap();
611  for (int i=0;i<layercount ;i++ ) {
612  if (initialized[i]) {
613  free(mblocks[i]->mempointer);
614  free(mblocks[i]);
615  }
616  } /* endfor */
617 }
618 
619 
621 {
622 
623  switch (id ) {
624  case 1: {
625  if (initialized[layer] == false ) {
628  initialized[layer] = true;
629  switch (layer) {
630  case clland : {
633  plasma.memblock->color[2] = cwater;
635  plasma.memblock->color[4] = cland;
636  plasma.memblock->color[5] = cmount;
637  plasma.memblock->tilevalcount = 5; // {anzahl Values -1 ( immer h�chster Wert in der [-Klammer) Montlayer �ndern !!!}
638  strcpy(plasma.memblock->bordername[0],"Deep-water");
639  strcpy(plasma.memblock->bordername[1],"Medium-water");
640  strcpy(plasma.memblock->bordername[2],"Shallow-water");
641  strcpy(plasma.memblock->bordername[3],"Land");
642  strcpy(plasma.memblock->bordername[4],"Mountain");
643  showland=true;
644  addbutton("~M~ap",10,397,50,405,3,1,21,true);
646  enablebutton(21);
648  }
649  break;
650  case clforest : {
651  plasma.memblock->color[0] = cland;
654  strcpy(plasma.memblock->bordername[0],"Forest");
655  showforest = true;
656  addbutton("~F~orest",60,397,120,405,3,1,22,true); //maximaler x-wert 340 -> barsize-buttons
658  enablebutton(22);
659  }
660  break;
661  case cldesert : {
662  plasma.memblock->color[0] = cland;
665  strcpy(plasma.memblock->bordername[0],"Desert");
666  showdesert=true;
667  addbutton("~D~esert",130,397,190,405,3,1,23,true);
669  enablebutton(23);
670  }
671  break;
672  case clmaterial: {
678  strcpy(plasma.memblock->bordername[0],"Few Material");
679  strcpy(plasma.memblock->bordername[1],"Medium Material");
680  strcpy(plasma.memblock->bordername[2],"Much Material");
681  showmaterial=true;
682  addbutton("~M~aterial",200,397,260,405,3,1,24,true);
684  enablebutton(24);
685  }
686  break;
687  case clfuel: {
693  strcpy(plasma.memblock->bordername[0],"Few Fuel");
694  strcpy(plasma.memblock->bordername[1],"Medium Fuel");
695  strcpy(plasma.memblock->bordername[2],"Much Fuel");
696  showfuel=true;
697  addbutton("~F~uel",270,397,330,405,3,1,25,true);
699  enablebutton(25);
700  }
701  break;
702  } /* endswitch */
703 
704  plasma.memblock->actpres = 0; // Damit Tilevalues neu gesetzt werden
709  bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
712  enablebutton(2);
713  }
715  plasma.memblock->res = res;
716  if (plasma.memblock->actpres != pres ) {
717  plasma.generateplasma(true);
719  enablebutton(2);
720  addeingabe(2,&tileval,0,pres);
721  }
722  else plasma.generateplasma(false);
724  showmap();
725  }
726  break;
727  case 2 : if (initialized[layer] == true ) {
729  int i;
730  if (correctvalues == true ) {
731  for (i=0 ;i < plasma.memblock->acttile ;i++) {
734  } /* endfor */
735  for (i=plasma.memblock->acttile+1;i < plasma.memblock->tilevalcount;i++ ) {
738  } /* endfor */
739  }
740  if ( (calculatevalues == true ) && (plasma.memblock->acttile < plasma.memblock->tilevalcount) ) {
743  int add = div / count;
744  if (add > 0) {
745  for (i=plasma.memblock->acttile+1;i < plasma.memblock->tilevalcount;i++ ) {
747  } /* endfor */
748  }
749  }
750  showmap();
751  }
752  break;
753  case 6 : if (initialized[layer] == true ){
754  tileval++;
755  enablebutton(2);
757  showmap();
758  }
759  break;
760  case 5 : if (initialized[layer] == true ){
761  tileval--;
762  enablebutton(2);
764  showmap();
765  }
766  break;
767  case 11 :
768  case 12 : if ( (initialized[layer] == true ) && ( plasma.memblock->tilevalcount >1 ) ) {
769  if (id == 11) {
772  } else {
774  else plasma.memblock->acttile = 0;
775  } /* endif */
780  bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
783  enablebutton(2);
784  }
785  break;
786  case 7 :
787  case 8 : {
788  if (id == 7) {
789  if (layer > 0) layer--;
790  else layer = layercount -1;
791  } else {
792  if (layer < layercount -1 ) layer++;
793  else layer = 0;
794  } /* endif */
800  bar(x1 + 501,y1 + 51,x1 + 579,y1 + 69,lightgray);
801  showtext2(clayer[layer],x1+505,y1+52);
802 
803  bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
804 
805  if (initialized[layer] == true ) {
808  res = plasma.memblock->res;
809  addeingabe(2,&tileval,0,pres);
810  enablebutton(2);
811  enablebutton(3);
812  enablebutton(4);
813 
814  plasma.memblock->actpres = 0; // Damit Tilevalues neu gesetzt werden
821  enablebutton(2);
822  }
823  }
824  break;
825  case 9 : if (initialized[layer] == true ){
826  plasma.flip = flip;
827  showmap();
828  }
829  break;
830  case 13 :
831  case 14 :
832  case 15 :
833  case 16 :
834  case 17 : if (id -12 != barsize ) {
835  barsize = id -12;
836  resetmapfield();
838  }
839  break;
840  case 21 :
841  case 22 :
842  case 23 :
843  case 24 :
844  case 25 : {
845  resetmapfield();
846  showmap();
847  }
848  break;
849  case 19: action = 2;
850  break;
851  case 20: action = 3;
852  break;
853  } /* endswitch */
854 
855 
856 }
857 
858 int mapgenerator(void)
859 {
860  tmapgenerator mg;
861 
862  mg.init();
863  mg.run();
864  mg.done();
865  return 0;
866 }
867 
868 int random2( int max)
869 {
870  if (max <= 1 ) return 0;
871  int div = RAND_MAX;
872  div /= (max -1);
873  int r = rand();
874  return r / (div + 1);
875 }
876 
878 {
879  maxvalue=300;
880  maxx = 200;
881  maxy = 150;
882  flip=false;
883  xsymm = 0;
884  ysymm = 0;
885 
886 }
887 
889 {
890  memblock = new (tmemoryblock);
891  memblock->startblocksize = 30000;
892  memblock->res = 4;
893  memblock->generated = false;
894  memblock->color[0] = 0;
895  memblock->color[1] = 1;
896  memblock->color[2] = 2;
898  memblock->acttile = 0;
899  memblock->tilevalcount = 2;
900 
901  blockcount = maxx * maxy;
902 
903  memblock->mempointer = new int[ blockcount ];
904  return 0;
905 }
906 
907 /*void tplasma::preview(word sx, word sy, word barsize)
908 {
909  register x,y;
910  register i;
911 
912  x = sx;
913  y = sy;
914 
915  if (flip == true) {
916  for (i=blockcount-1;i>0 ;i-- ) {
917  if ( barsize <= 1 ) {
918  if (memblock->mempointer[i] > memblock->tilevalue1 ) {
919  if (memblock->mempointer[i] <= memblock->tilevalue2 ) putpixel(x,y, memblock->col2);
920  else putpixel(x,y, memblock->col3);
921  }
922  else putpixel(x,y, memblock->col1);
923  }
924  else {
925  if (memblock->mempointer[i] > memblock->tilevalue1 ) {
926  if (memblock->mempointer[i] <= memblock->tilevalue2 ) bar(x,y,x+barsize,y+barsize,memblock->col2);
927  else bar(x,y,x+barsize,y+barsize,memblock->col3);
928  }
929  else bar(x,y,x+barsize,y+barsize,memblock->col1);
930  }
931  x += barsize;
932  if (x >= sx + (maxx-1) * barsize ) {
933  x = sx;
934  y += barsize;
935  }
936  }
937  } else {
938  for (i=0;i<blockcount-1;i++ ) {
939  if ( barsize <= 1 ) {
940  if (memblock->mempointer[i] > memblock->tilevalue1 ) {
941  if (memblock->mempointer[i] <= memblock->tilevalue2 ) putpixel(x,y, memblock->col2);
942  else putpixel(x,y, memblock->col3);
943  }
944  else putpixel(x,y, memblock->col1);
945  }
946  else {
947  if (memblock->mempointer[i] > memblock->tilevalue1 ) {
948  if (memblock->mempointer[i] <= memblock->tilevalue2 ) bar(x,y,x+barsize-1,y+barsize-1,memblock->col2);
949  else bar(x,y,x+barsize-1,y+barsize-1,memblock->col3);
950  }
951  else bar(x,y,x+barsize-1,y+barsize-1,memblock->col1);
952  }
953  x += barsize;
954  if (x >= sx + (maxx-1) * barsize ) {
955  x = sx;
956  y += barsize;
957  }
958  }
959  }
960 }
961 
962 void tplasma::process(word sx, word sy,word barsize)
963 {
964  creatememblock();
965  generateplasma(true);
966  preview(sx,sy,barsize);
967  showtext2(strrr(memblock->tilevalue1),500,100);
968  do {
969  ch = r_key();
970  switch (ch) {
971  case ct_p : {
972  memblock->tilevalue1++;
973  preview(sx,sy,barsize);
974  showtext2(strrr(memblock->tilevalue1),500,100);
975  }
976  break;
977  case ct_o : {
978  memblock->tilevalue1--;
979  preview(sx,sy,barsize);
980  showtext2(strrr(memblock->tilevalue1),500,100);
981  }
982  break;
983  case ct_l : {
984  memblock->tilevalue2++;
985  preview(sx,sy,barsize);
986  showtext2(strrr(memblock->tilevalue2),500,200);
987  }
988  break;
989  case ct_k : {
990  memblock->tilevalue2--;
991  preview(sx,sy,barsize);
992  showtext2(strrr(memblock->tilevalue2),500,200);
993  }
994  break;
995  case ct_f :
996  if (flip == true) flip = false;
997  else flip = true;
998  preview(sx,sy,barsize);
999  break;
1000  case ct_enter : {
1001  generateplasma(false);
1002  memblock->tilevalue1 = memblock->maxset / 2;
1003  preview(sx,sy,barsize);
1004  showtext2(strrr(memblock->tilevalue1),500,100);
1005  }
1006  break;
1007  }
1008  } while (ch != ct_esc );
1009 }*/
1010 
1011 int tplasma::getmem(int x, int y)
1012 {
1013  if (x >= maxx ) x -= maxx;
1014  if (y >= maxy ) y -= maxy;
1015  return memblock->mempointer[ x + (y * maxx ) ] ;
1016 }
1017 
1018 
1019 void tplasma::setmemory(int x, int y, int color)
1020 {
1021  if (x >= maxx ) x -= maxx;
1022  if (y >= maxy ) y -= maxy;
1023  memblock->mempointer[ x + (y * maxx ) ] = color;
1024 }
1025 
1026 void tplasma::membar( int x1 ,int y1 ,int x2 ,int y2, int color )
1027 { int exc;
1028  if (x1 >x2) {
1029  exc = x1;
1030  x1 = x2;
1031  x2 = exc;
1032  }
1033 
1034  if (y1 >y2) {
1035  exc = y1 ;
1036  y1 = y2 ;
1037  y2 = exc ;
1038  }
1039 
1040  for (int j=y1;j<=y2;j++ ) {
1041  for (int i=x1;i<=x2;i++) {
1042  //memblock->mempointer[ i + (j * maxx ) ] = color;
1043  setmemory(i,j,color);
1044  } /* endfor */
1045  } /* endfor */
1046 }
1047 
1048 
1049 
1050 void tplasma::generateplasma(Uint8 resettile)
1051 {
1052  int colour;
1053  int sblocksize;
1054 
1056 
1058 
1059  blocksize /= memblock->res;
1060 
1061  sblocksize = blocksize;
1062 
1063  //memset(memblock->mempointer,0,blockcount * 2);
1064  //memset(memblock->mempointer,0,sizeof(*memblock->mempointer));
1065 
1066  memblock->generated = true;
1067 
1068  if (resettile == true ) {
1069  for (int i=0;i<memblock->tilevalcount;i++ ) {
1070  memblock->tileval[i] = ( memblock->maxset / ( memblock->tilevalcount +1 ) ) * (i +1 );
1071  } /* endfor */
1072  } else {
1073  for (int i=0;i<memblock->tilevalcount;i++ ) {
1075  } /* endfor */
1076  } /* endif */
1077 
1078 
1079  // ## MB
1080  int maxy_local = maxy;
1081  #ifdef cheatsymmetry
1082  maxy_local /= 2;
1083  #endif
1084 
1085  do {
1086  for(register int y = 0; y < (maxy_local / blocksize) + 1; y++) {
1087  for(register int x = 0; x < (maxx / blocksize) + 1; x++) {
1088  /*if(keypress()) {
1089  r_key();
1090  return 1;
1091  }*/
1092  if(blocksize == sblocksize) {
1093  colour = random2(memblock->maxset + 1);
1094  if( random2(5000) > 3500)
1095  colour = 1 + memblock->maxset - random2(memblock->maxset / (1 + random2(8)));
1096  colour %= (memblock->maxset + 1);
1097  }
1098  else {
1099  colour = getmem(x * blocksize >= maxx ? 0 : x * blocksize + blocksize,y * blocksize);
1100  colour += getmem(x * blocksize,y * blocksize < 2 * blocksize ? maxy_local : y * blocksize - blocksize);
1101  colour += getmem(x * blocksize < 2 * blocksize ? maxx : x * blocksize - blocksize,y * blocksize);
1102  colour += getmem(x * blocksize,y * blocksize > maxy_local - blocksize ? 0 : y * blocksize + blocksize);
1103 
1104  //colour = memblock->mempointer[ (x * blocksize >= maxx ? 0 : x * blocksize + blocksize) + ( ( y * blocksize ) * maxx ) ];
1105  //colour += memblock->mempointer[ (x * blocksize ) + ((y * blocksize < 2 * blocksize ? maxy_local : y * blocksize - blocksize) * maxx ) ];
1106  //colour += memblock->mempointer[ (x * blocksize < 2 * blocksize ? maxx : x * blocksize - blocksize) + ((y * blocksize) * maxx ) ];
1107  //colour += memblock->mempointer[ (x * blocksize) + ((y * blocksize < 2 * blocksize ? maxy_local : y * blocksize - blocksize) * maxx ) ];
1108  colour /= 4;
1109  }
1110  if(blocksize != 1) membar(x * blocksize, y * blocksize, x * blocksize + blocksize - 1, y * blocksize + blocksize - 1,colour);
1111  else setmemory(x,y,colour);
1112  //memblock->mempointer[ x + (y * maxx ) ] = colour;
1113  }
1114  }
1115  blocksize /= 2;
1116  } while(blocksize > 0);
1117 
1118  // ## MB
1119  if ( ysymm )
1120  for(int y = maxy/2; y < maxy; y++)
1121  for(int x = 0; x < maxx ; x++)
1122  setmemory(x , y, getmem ( x, maxy-y ));
1123 
1124  if ( xsymm )
1125  for(int x = maxx/2; x < maxx ; x++)
1126  for(int y = 0; y < maxy; y++)
1127  setmemory(x , y, getmem ( maxx-x, y ));
1128 
1129 
1130  //showmemory();
1131 }
#define centerlayer
Definition: edgen.cpp:34
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
pterraintype btyp[numofbdts]
Definition: edgen.cpp:64
tfontsettings activefontsettings
Definition: newfont.cpp:51
void setfuel(int number)
Definition: edgen.cpp:503
Uint8 background
Definition: newfont.h:171
void showmontlayer(int sx, int sy, int barsize)
Definition: edgen.cpp:275
void montlayer(int layer)
Definition: edgen.cpp:207
int x1
Definition: dlg_box.h:40
int xsize
the size of the map
Definition: gamemap.h:201
#define cforest
Definition: edgen.h:80
int actpres
Definition: edgen.h:105
void showmap(void)
Definition: edgen.cpp:368
void membar(int x1, int y1, int x2, int y2, int color)
Definition: edgen.cpp:1026
Vehicle * vehicle
Definition: mapfield.h:89
#define cshallowwater
Definition: edgen.h:76
int y1
Definition: dlg_box.h:40
virtual void run(void)
Definition: dlg_box.cpp:1477
int color[maxtilevals+1]
Definition: edgen.h:107
class TerrainType * pterraintype
Definition: terraintype.h:72
Definition: edgen.h:117
Uint8 material
Definition: mapfield.h:54
int overwritecolor[maxoverwrite]
Definition: edgen.cpp:65
#define cwater
Definition: edgen.h:75
int xsize
Definition: dlg_box.h:40
void rahmen(bool invers, int x1, int y1, int x2, int y2)
Definition: dlgraph.cpp:97
#define maxoverwrite
Definition: edgen.cpp:35
#define cmuchmaterial
Definition: edgen.h:86
const char * clayer[layercount]
Definition: edgen.cpp:69
Uint8 calculatevalues
Definition: edgen.cpp:55
#define ct_left
Definition: keysymbols.h:120
#define cverydeepwater
Definition: edgen.h:73
int res
Definition: edgen.h:106
void buildgraphics(void)
Definition: dlg_box.cpp:1180
pfont smallarial
Definition: spfst-legacy.h:28
int maxx
Definition: edgen.h:119
void addcoast(void)
Definition: edgen.cpp:389
Uint8 justify
Definition: newfont.h:176
int mapgenerator(void)
Definition: edgen.cpp:858
#define lefttext
Definition: newfont.h:184
Global platform dependant definitions. This file just branches to the platform specific files in thei...
a single field of the map
Definition: mapfield.h:26
void resetmapfield(void)
Definition: edgen.cpp:599
void setmaterial(int number)
Definition: edgen.cpp:491
int barsize
Definition: edgen.cpp:59
#define blocksize
Definition: dialog.cpp:1428
virtual void run(void)
Definition: edgen.cpp:604
Uint8 showfuel
Definition: edgen.cpp:55
int whereland
Definition: edgen.cpp:60
Uint8 color
Definition: newfont.h:170
int terrain_object_ids[numofbdts][2][2]
Definition: edgen.cpp:516
void setmemory(int x, int y, int color)
Definition: edgen.cpp:1019
Uint8 correctvalues
Definition: edgen.cpp:55
tkey taste
Definition: dlg_box.h:88
#define clland
Definition: edgen.h:96
int ysize
Definition: dlg_box.h:40
Uint8 * constructionlayer
Definition: edgen.cpp:57
int tileval
Definition: edgen.cpp:61
MapField * getfield(int x, int y)
returns the field at the given coordinates
Definition: spfst.cpp:199
int tileval[maxtilevals]
Definition: edgen.h:108
#define ct_5
Definition: keysymbols.h:112
pfont font
Definition: newfont.h:169
int terrainaccessible(const MapField *field, const Vehicle *vehicle, int uheight)
Checks if the unit can drive on the field.
Definition: spfst.cpp:70
Schriften schriften
Definition: spfst.cpp:66
Uint8 flip
Definition: edgen.h:120
void done(void)
Definition: dlg_box.cpp:1235
bool mapsaved
Definition: edmisc.cpp:66
#define enhance
Definition: edgen.cpp:489
int acttile
Definition: edgen.h:112
TerrainBits getTerrainBitType(TerrainBitTypes tbt)
char * strrr(int a)
converts a to a string.
Definition: misc.cpp:66
int windowstyle
Definition: dlg_box.h:163
tplasma plasma
Definition: edgen.cpp:62
#define ct_plus
Definition: keysymbols.h:53
#define ct_4
Definition: keysymbols.h:111
bool initialized[layercount]
Definition: edgen.cpp:56
ItemRepositoryLoader< TerrainType > terrainTypeRepository("terraintype")
pmemoryblock mblocks[layercount]
Definition: edgen.cpp:63
int action
Definition: edgen.cpp:39
int * mempointer
Definition: edgen.h:104
Uint8 fuel
mineral resources on this field.
Definition: mapfield.h:54
#define clforest
Definition: edgen.h:97
int maxbarsize
Definition: edgen.cpp:59
void setparams(ObjectRemovalStrategy *objectRemovalStrategy)
recalculates the terrain properties, movemalus etc from the terraintype and the objects,
Definition: mapfield.cpp:605
int startblocksize
Definition: edgen.h:111
void init(void)
Definition: edgen.cpp:72
char bordername[maxtilevals][20]
Definition: edgen.h:109
#define cfewmaterial
Definition: edgen.h:84
#define ct_minus
Definition: keysymbols.h:52
#define numofbdts
Definition: edgen.h:92
void addbutton(const char *ltxt, int lx1, int ly1, int lx2, int ly2, int lart, int lstyle, int lid, bool enabled)
Definition: dlg_box.cpp:471
int tilevalcount
Definition: edgen.h:112
#define ct_esc
Definition: keysymbols.h:43
Dialog classes based on the Paragui library.
#define cmount
Definition: edgen.h:78
Uint16 length
Definition: newfont.h:174
void putpixel(int x1, int y1, int color)
puts a single pixel on the screen. This is one of the few functions that work in truecolor mode too ...
Definition: basegfx.cpp:717
#define cmediumfuel
Definition: edgen.h:89
Uint8 flip
Definition: edgen.cpp:55
void bar(tmouserect rect, int color)
Definition: dlg_box.cpp:537
#define cdeepwater
Definition: edgen.h:74
#define cmuchfuel
Definition: edgen.h:90
#define clfuel
Definition: edgen.h:100
#define cland
Definition: edgen.h:77
int maxvalue
Definition: edgen.h:119
int blockcount
Definition: edgen.h:121
#define cdesert
Definition: edgen.h:82
void addkey(int id, tkey key)
Definition: dlg_box.cpp:774
const int red
Definition: basegfx.h:91
void generatefinishmap(void)
Definition: edgen.cpp:345
int maxset
Definition: edgen.h:105
int matdiv[3]
Definition: edgen.cpp:486
virtual void buttonpressed(int id)
Definition: edgen.cpp:620
int ysize
Definition: gamemap.h:201
MapField * pf
Definition: edgen.cpp:66
void showtext2(const ASCString &text, int x, int y)
Definition: basegfx.cpp:1953
pmemoryblock memblock
Definition: edgen.h:122
#define ct_1
Definition: keysymbols.h:108
Uint8 showland
Definition: edgen.cpp:55
void help(int id)
displays a dialogbog with the given help topic
Definition: dlg_box.cpp:3286
#define ct_right
Definition: keysymbols.h:121
Uint8 generated
Definition: edgen.h:110
int getmem(int x, int y)
Definition: edgen.cpp:1011
MapField * field
the array of fields
Definition: gamemap.h:204
int maxy
Definition: edgen.h:119
Uint8 checkland(int x, int y)
Definition: edgen.cpp:381
#define ct_up
Definition: keysymbols.h:122
Uint8 showforest
Definition: edgen.cpp:55
#define cfewfuel
Definition: edgen.h:88
int xsymm
Definition: edgen.h:132
int actlayer
Definition: edgen.cpp:58
#define ct_3
Definition: keysymbols.h:110
#define cmediummaterial
Definition: edgen.h:85
virtual void enablebutton(int id)
Definition: dlg_box.cpp:860
#define dlg_in3d
Definition: dlg_box.h:33
GameMap * actmap
Definition: spfst.cpp:64
void init(void)
Definition: dlg_box.cpp:314
tplasma(void)
Definition: edgen.cpp:877
#define cldesert
Definition: edgen.h:98
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
#define ct_f1
Definition: keysymbols.h:132
int choice_dlg(const ASCString &title, const ASCString &leftButton, const ASCString &rightButton)
Definition: dialog.cpp:616
int overwritecolorcount
Definition: edgen.cpp:61
#define ct_down
Definition: keysymbols.h:123
Uint8 showdesert
Definition: edgen.cpp:55
#define layercount
Definition: edgen.cpp:33
int ysymm
Definition: edgen.h:132
void setpfield(int number)
Definition: edgen.cpp:462
void mousevisible(int an)
Definition: events.cpp:75
void addeingabe(int lid, void *data, int min, int max)
Definition: dlg_box.cpp:833
#define clmaterial
Definition: edgen.h:99
Uint8 showmaterial
Definition: edgen.cpp:55
#define ct_2
Definition: keysymbols.h:109
void generateplasma(Uint8 resettile)
Definition: edgen.cpp:1050
const int lightgray
Definition: basegfx.h:94
int random2(int max)
Definition: edgen.cpp:868
void setmap(void)
Definition: edgen.cpp:529
const char * title
Definition: dlg_box.h:162
#define ctransparent
Definition: edgen.h:94
int fueldiv[3]
Definition: edgen.cpp:487
int creatememblock(void)
Definition: edgen.cpp:888