00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "global.h"
00026 #include "edmisc.h"
00027 #include "edgen.h"
00028 #include "vehicletype.h"
00029 #include "itemrepository.h"
00030 #include "paradialog.h"
00031
00032 #define layercount 5
00033 #define centerlayer 65000
00034 #define maxoverwrite 5
00035
00036 class tmapgenerator : public tdialogbox {
00037 public :
00038 int action;
00039 void init(void);
00040 void showmap(void);
00041 void generatefinishmap(void);
00042 void montlayer(int layer);
00043 void showmontlayer( int sx, int sy, int barsize);
00044 void setpfield(int number);
00045 void setmaterial(int number);
00046 void setfuel(int number);
00047 void resetmapfield(void);
00048 void addcoast(void);
00049 void setmap(void);
00050 char checkland(int x, int y);
00051 virtual void run(void);
00052 virtual void buttonpressed(int id);
00053 protected :
00054 char flip,showland,showdesert,showforest,showmaterial,showfuel,correctvalues,calculatevalues;
00055 char initialized[ layercount ];
00056 char *constructionlayer;
00057 int layer,actlayer;
00058 int barsize,maxbarsize;
00059 int whereland;
00060 int tileval,res,pres,overwritecolorcount;
00061 tplasma plasma;
00062 pmemoryblock mblocks[ layercount ];
00063 pterraintype btyp[numofbdts];
00064 int overwritecolor[maxoverwrite];
00065 tfield* pf;
00066 };
00067
00068 const char* clayer[layercount] = {"Land", "Forest", "Desert","Material","Fuel"};
00069
00070
00071 void tmapgenerator::init(void)
00072 {
00073 int w;
00074 char s1[100],s2[100];
00075
00076 tdialogbox::init();
00077 action = 0;
00078 title = "Map generator";
00079 x1 = 10;
00080 xsize = 620;
00081 y1 = 10;
00082 ysize = 460;
00083
00084 w = (xsize - 160) / 2;
00085 windowstyle = windowstyle ^ dlg_in3d;
00086
00087 for (int i=0;i < layercount ;i++ ) initialized[i] =false;
00088
00089 plasma.maxx = actmap->xsize * 2;
00090 plasma.maxy = actmap->ysize;
00091 flip = plasma.flip;
00092 res = 10;
00093 if (res > plasma.maxx / 5) res = plasma.maxx / 5;
00094 pres = 300;
00095 tileval = 0;
00096 actlayer = layer = 0;
00097
00098
00099 int xmax = 430 / plasma.maxx;
00100 int ymax = 340 / plasma.maxy;
00101
00102 if (xmax > ymax ) maxbarsize = ymax;
00103 else maxbarsize = xmax;
00104
00105 barsize = maxbarsize;
00106
00107 constructionlayer = new ( char[plasma.maxx * plasma.maxy ]);
00108
00109 addbutton("",480,80,510,100,0,1,7,true);
00110 addkey(7,ct_down);
00111 addbutton("",530,80,560,100,0,1,8,true);
00112 addkey(8,ct_up);
00113
00114 addbutton("~G~enerate new",460,115,580,135,0,1,1,true);
00115
00116 addbutton("~R~esolution",460,155,580,175,2,1,3,true);
00117 addeingabe(3,&res,1,plasma.maxx / 5);
00118
00119 addbutton("~P~recission",460,195,580,215,2,1,4,true);
00120 addeingabe(4,&pres,0,30000);
00121
00122 addbutton("~F~lip map",480,225,580,240,3,1,9,true);
00123 addeingabe(9,&flip,0,lightgray);
00124
00125 addbutton("",460,295,580,315,2,1,2,true);
00126 addeingabe(2,&tileval,0,pres);
00127
00128 addbutton("-",480,330,510,350,0,1,5,true);
00129 addkey(5,ct_minus);
00130 addbutton("+",530,330,560,350,0,1,6,true);
00131 addkey(6,ct_plus);
00132
00133 addbutton("",480,370,510,390,0,1,11,true);
00134 addkey(11,ct_left);
00135 addbutton("",530,370,560,390,0,1,12,true);
00136 addkey(12,ct_right);
00137
00138 correctvalues = true;
00139 addbutton("Co~r~rect",520,410,600,420,3,1,50,true);
00140 addeingabe(50,&correctvalues,0,lightgray);
00141
00142 calculatevalues = true;
00143 addbutton("Ca~l~culate",520,430,600,440,3,1,51,true);
00144 addeingabe(51,&calculatevalues,0,lightgray);
00145
00146 if ( maxbarsize >=1 ) addbutton("1",345,395,360,410,0,1,13,true);
00147 addkey(13,ct_1);
00148 if ( maxbarsize >=2 ) addbutton("2",365,395,380,410,0,1,14,true);
00149 addkey(14,ct_2);
00150 if ( maxbarsize >=3 ) addbutton("3",385,395,400,410,0,1,15,true);
00151 addkey(15,ct_3);
00152 if ( maxbarsize >=4 ) addbutton("4",405,395,420,410,0,1,16,true);
00153 addkey(16,ct_4);
00154 if ( maxbarsize >=5 ) addbutton("5",425,395,440,410,0,1,17,true);
00155 addkey(17,ct_5);
00156
00157 addbutton ("~x~sym", 455,20,500,30, 3, 0, 31, true );
00158 addeingabe ( 31, &plasma.xsymm, 0, lightgray );
00159
00160 addbutton ("~y~sym", 510,20,560,30, 3, 0, 32, true );
00161 addeingabe ( 32, &plasma.ysymm, 0, lightgray );
00162
00163 addbutton("~A~ccept Map",20,ysize - 40,20 + w,ysize - 10,0,1,19,true);
00164 addbutton("~C~ancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,20,true);
00165
00166 buildgraphics();
00167
00168 activefontsettings.font = schriften.smallarial;
00169 activefontsettings.color = red;
00170 activefontsettings.background = lightgray;
00171 activefontsettings.length = 70;
00172 activefontsettings.justify = lefttext;
00173
00174 showtext2("Layer",x1+460,y1+52);
00175 rahmen(true,x1 + 500,y1 + 50,x1 + 580,y1 + 70);
00176 showtext2(clayer[layer],x1+505,y1+52);
00177
00178 showtext2("Limit",x1+460,y1+267);
00179 rahmen(true,x1 + 500,y1 + 265,x1 + 580,y1 + 285);
00180
00181 strcpy(s1,"XSize : ");
00182 strcpy(s2,"YSize : ");
00183 showtext2(strcat(s1,strrr(plasma.maxx)),x1+10,y1+10);
00184 showtext2(strcat(s2,strrr(plasma.maxy)),x1+120,y1+10);
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 rahmen(true,x1 + 450,y1 + 40,x1 + 590,y1 + 400);
00195 rahmen(true,x1 + 10,y1 + 40,x1 + 440,y1 + 390);
00196
00197
00198
00199
00200
00201
00202 mousevisible(true);
00203 }
00204
00205
00206 void tmapgenerator::montlayer(int layer)
00207 {
00208 int i,j;
00209 char found;
00210
00211 if ( overwritecolorcount == 0 ){
00212 for (i=0;i<plasma.blockcount;i++ ) {
00213 found = false;
00214 j=0;
00215 do {
00216 if (mblocks[layer]->mempointer[i] <= mblocks[layer]->tileval[j] ) {
00217 if ( mblocks[layer]->color[j] != ctransparent ) constructionlayer[i] = mblocks[layer]->color[j];
00218 found = true;
00219 }
00220 else j++;
00221 } while ( ( found == false ) && (j < mblocks[layer]->tilevalcount ) );
00222 if ( (j == mblocks[layer]->tilevalcount ) && ( mblocks[layer]->color[int(mblocks[layer]->tilevalcount)] != ctransparent ) )
00223 constructionlayer[i] = mblocks[layer]->color[int(mblocks[layer]->tilevalcount)];
00224 }
00225 } else {
00226 for (i=0;i<plasma.blockcount;i++ ) {
00227 for (int k=0;k<overwritecolorcount;k++ ) {
00228 if (constructionlayer[i] == overwritecolor[k]) {
00229 found = false;
00230 j=0;
00231 do {
00232 if (mblocks[layer]->mempointer[i] <= mblocks[layer]->tileval[j] ) {
00233 constructionlayer[i] = mblocks[layer]->color[j];
00234 found = true;
00235 }
00236 else j++;
00237 } while ( ( found == false ) && (j < mblocks[layer]->tilevalcount ) );
00238 if (j == mblocks[layer]->tilevalcount )
00239 constructionlayer[i] = mblocks[layer]->color[int(mblocks[layer]->tilevalcount)];
00240 }
00241 }
00242 }
00243 }
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 void tmapgenerator::showmontlayer(int sx, int sy, int barsize)
00275 {
00276 int i;
00277
00278 int prevx,prevy;
00279
00280
00281
00282
00283 prevx = x1 + 15 + (430 - plasma.maxx * barsize ) / 2;
00284 prevy = y1 + 45 + (340 - plasma.maxy * barsize ) / 2;
00285
00286 if (sx == centerlayer) sx = prevx;
00287 if (sy == centerlayer) sy = prevy;
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 int x,y;
00317
00318 x = sx;
00319 y = sy;
00320
00321 if (flip == true) {
00322 for (i=plasma.blockcount-1;i>=0 ;i-- ) {
00323 if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
00324 else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
00325 x += barsize;
00326 if (x >= sx + (plasma.maxx) * barsize ) {
00327 x = sx;
00328 y += barsize;
00329 }
00330 }
00331 } else {
00332 for (i=0;i<plasma.blockcount;i++ ) {
00333 if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
00334 else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
00335 x += barsize;
00336 if (x >= sx + (plasma.maxx) * barsize ) {
00337 x = sx;
00338 y += barsize;
00339 }
00340 }
00341 }
00342 }
00343
00344 void tmapgenerator::generatefinishmap(void)
00345 {
00346 overwritecolorcount = 0;
00347 if ( (showland == true ) && (initialized[0] == true ) ) montlayer(0);
00348 else memset(constructionlayer,lightgray,plasma.blockcount);
00349
00350 overwritecolorcount = 2;
00351 overwritecolor[0] = mblocks[clland]->color[4];
00352 overwritecolor[1] = lightgray;
00353 if ( (showforest == true ) && (initialized[1] == true ) ) montlayer(1);
00354
00355 overwritecolorcount = 2;
00356 overwritecolor[0] = mblocks[clland]->color[4];
00357 overwritecolor[1] = lightgray;
00358 if ( (showdesert == true ) && (initialized[2] == true ) ) montlayer(2);
00359 }
00360
00361
00362
00363
00364
00365
00366
00367 void tmapgenerator::showmap(void)
00368 {
00369 generatefinishmap();
00370
00371 overwritecolorcount = 0;
00372 if ( (showmaterial == true ) && (initialized[3] == true ) ) montlayer(3);
00373
00374 overwritecolorcount = 0;
00375 if ( (showfuel == true ) && (initialized[4] == true ) ) montlayer(4);
00376
00377 showmontlayer(centerlayer,centerlayer,barsize);
00378 }
00379
00380 char tmapgenerator::checkland(int x, int y)
00381 {
00382 if ( ( getfield(x,y)->typ->art & getTerrainBitType(cbwater) ).none() )
00383 return true;
00384 else
00385 return false;
00386 }
00387
00388 void tmapgenerator::addcoast(void)
00389 {
00390 tfield* pf;
00391 const int id[2]={42,83};
00392
00393 for (int i=0;i<2;i++ ) {
00394 if (id[i] != 0 ) {
00395 btyp[i] = terrainTypeRepository.getObject_byID(id[i]);
00396 if (btyp[i] == NULL) btyp[i] = terrainTypeRepository.getObject_byPos(0);
00397 }
00398 }
00399
00400
00401
00402 for (int y=0;y<actmap->ysize ;y++ ) {
00403 for (int x=0;x<actmap->xsize ;x++) {
00404 pf = getfield(x,y);
00405 whereland = 0;
00406 if ( checkland(x,y) == false ){
00407 if ( (x >1 ) && (y >1 ) && (y < actmap->ysize-2 ) && ( x < actmap->xsize -2) ){
00408 if ( checkland(x+1, y) ) whereland |= 4;
00409 if ( checkland(x-1, y) ) whereland |= 64;
00410 if ( checkland(x, y+2) ) whereland |= 16;
00411 if ( checkland(x, y-2) ) whereland |= 1;
00412 if (y & 1) {
00413 if ( checkland(x-1, y-1) ) whereland |= 128;
00414 if ( checkland(x, y-1) ) whereland |= 2;
00415 if ( checkland(x, y+1) ) whereland |= 8;
00416 if ( checkland(x-1, y+1) ) whereland |= 32;
00417 } else {
00418 if ( checkland(x, y-1) ) whereland |= 128;
00419 if ( checkland(x+1,y-1) ) whereland |= 2;
00420 if ( checkland(x+1, y+1) ) whereland |= 8;
00421 if ( checkland(x, y+1) ) whereland |= 32;
00422 }
00423 if (whereland & 1) {
00424 pf->typ = btyp[0]->weather[0];
00425
00426 }
00427 if (whereland & 2) {
00428 pf->typ = btyp[1]->weather[0];
00429
00430 }
00431 if (whereland & 4) {
00432 pf->typ = btyp[0]->weather[0];
00433
00434 }
00435 if (whereland & 8) {
00436 pf->typ = btyp[1]->weather[0];
00437
00438 }
00439 if (whereland & 16) {
00440 pf->typ = btyp[0]->weather[0];
00441
00442 }
00443 if (whereland & 32) {
00444 pf->typ = btyp[1]->weather[0];
00445
00446 }
00447 if (whereland & 64) {
00448 pf->typ = btyp[0]->weather[0];
00449
00450 }
00451 if (whereland & 128) {
00452 pf->typ = btyp[1]->weather[0];
00453
00454 }
00455 }
00456 }
00457 }
00458 }
00459 }
00460
00461 void tmapgenerator::setpfield(int number)
00462 {
00463 switch ( constructionlayer[ number ] ) {
00464 case cwater : pf->typ = btyp[0]->weather[0];
00465 break;
00466 case cland : pf->typ = btyp[1]->weather[0];
00467 break;
00468 case cmount : pf->typ = btyp[2]->weather[0];
00469 break;
00470 case cforest : pf->typ = btyp[3]->weather[0];
00471 break;
00472 case cdesert : pf->typ = btyp[4]->weather[0];
00473 break;
00474 case cshallowwater : pf->typ = btyp[5]->weather[0];
00475 break;
00476 case cdeepwater : pf->typ = btyp[6]->weather[0];
00477 break;
00478 case cverydeepwater : pf->typ = btyp[7]->weather[0];
00479 break;
00480 default: pf->typ = btyp[1]->weather[0];
00481 break;
00482 }
00483 }
00484
00485 int matdiv[3];
00486 int fueldiv[3];
00487
00488 #define enhance 1000
00489
00490 void tmapgenerator::setmaterial(int number)
00491 {
00492 for (int i =mblocks[clmaterial]->tilevalcount-1;i >=0 ;i-- ) {
00493 if (mblocks[clmaterial]->mempointer[number] > mblocks[clmaterial]->tileval[i] ) {
00494 int test = ( ( (mblocks[clmaterial]->mempointer[number] - mblocks[clmaterial]->tileval[i] ) * matdiv[i] / enhance ) + (i * 80)) * 14 / 10;
00495 if ( test > 255 ) pf->material = 255;
00496 else pf->material = test;
00497 return;
00498 }
00499 }
00500 }
00501
00502 void tmapgenerator::setfuel(int number)
00503 {
00504 for (int i =mblocks[clfuel]->tilevalcount-1;i >=0 ;i-- ) {
00505 if (mblocks[clfuel]->mempointer[number] > mblocks[clfuel]->tileval[i] ){
00506 int test = ( ( (mblocks[clfuel]->mempointer[number] - mblocks[clfuel]->tileval[i] ) * fueldiv[i] / enhance ) + (i * 80) ) * 14 / 10;
00507 if ( test>255 ) pf->fuel =255;
00508 else pf->fuel = test;
00509 return;
00510 }
00511 }
00512 }
00513
00514
00515 int terrain_object_ids[numofbdts][2][2] = {{{ 299, -1 }, { 307, -1 }},
00516 {{ 28 , -1 }, { 38 , -1 }},
00517 {{ 30 , -1 }, { 40 , -1 }},
00518 {{ 30 , -1 }, { 40 , -1 }},
00519 {{ 34 , -1 }, { 35 , -1 }},
00520 {{ 299, -1 }, { 307, -1 }},
00521 {{ 301, -1 }, { 308, -1 }},
00522 {{ 302, -1 }, { 309, -1 }},
00523 {{ 30 , -1 }, { 40 , -1 }},
00524 {{ 30 , -1 }, { 40 , -1 }},
00525 {{ 30 , -1 }, { 40 , -1 }},
00526 {{ 30 , -1 }, { 40 , -1 }}};
00527
00528 void tmapgenerator::setmap(void)
00529 {
00530
00531 int i,j;
00532
00533 generatefinishmap();
00534
00535 int set = 2 - choice_dlg("Choose terrain set","dark","light") ;
00536 for (i=0;i<numofbdts ;i++ ) {
00537 btyp[i] = terrainTypeRepository.getObject_byID( terrain_object_ids[i][set][0] );
00538 if ( !btyp[i] )
00539 btyp[i] = terrainTypeRepository.getObject_byPos(0);
00540 }
00541
00542 if (initialized[clmaterial] == true ) {
00543 matdiv[0] = 81 * enhance / ( mblocks[clmaterial]->tileval[1] -mblocks[clmaterial]->tileval[0] +1 ) ;
00544 matdiv[1] = 80 * enhance / ( mblocks[clmaterial]->tileval[2] - mblocks[clmaterial]->tileval[1] +1 );
00545 matdiv[2] = 95 * enhance / ( mblocks[clmaterial]->actpres - mblocks[clmaterial]->tileval[1] +1);
00546 }
00547
00548 if (initialized[clfuel] == true ) {
00549 fueldiv[0] = 81 * enhance / ( mblocks[clfuel]->tileval[1] -mblocks[clfuel]->tileval[0] +1);
00550 fueldiv[1] = 80 * enhance / ( mblocks[clfuel]->tileval[2] - mblocks[clfuel]->tileval[1] +1);
00551 fueldiv[2] = 95 * enhance / ( mblocks[clfuel]->actpres - mblocks[clfuel]->tileval[1] +1);
00552 }
00553
00554 if ( ( actmap->xsize * 2 == plasma.maxx ) && (actmap->ysize == plasma.maxy ) ){
00555 mapsaved = false;
00556 if (flip == true) {
00557 for (i=0;i< ( plasma.maxx / 2 ) ;i++ ) {
00558 for (j=0;j<plasma.maxy;j++ ) {
00559 pf = &actmap->field[ ( plasma.maxx / 2 - i - 1 ) + ( ( plasma.maxy - j -1) * plasma.maxx / 2 ) ];
00560 int plasmalayernr = ( i * 2 + ( j & 1 ) ) + ( j * plasma.maxx );
00561 setpfield ( plasmalayernr ) ;
00562 pf->setparams();
00563 if (initialized[clmaterial] == true ) setmaterial ( plasmalayernr );
00564 if (initialized[clfuel] ==true ) setfuel ( plasmalayernr );
00565 if ( pf->vehicle )
00566 if ( terrainaccessible(pf,pf->vehicle) == false ) {
00567 delete pf->vehicle;
00568 pf->vehicle = NULL;
00569 }
00570 }
00571 }
00572 } else {
00573 for (i=0;i< ( plasma.maxx / 2 ) ;i++ ) {
00574 for (j=0;j<plasma.maxy;j++ ) {
00575 pf = &actmap->field[i + ( j * plasma.maxx / 2 ) ];
00576 int plasmalayernr = ( i * 2 + ( j & 1 ) ) + ( j * plasma.maxx );
00577 setpfield ( plasmalayernr ) ;
00578 pf->setparams();
00579 if (initialized[clmaterial] == true ) setmaterial ( plasmalayernr );
00580 if (initialized[clfuel] ==true ) setfuel ( plasmalayernr );
00581 if ( pf->vehicle )
00582 if ( terrainaccessible(pf,pf->vehicle) == false ) {
00583 delete pf->vehicle;
00584 pf->vehicle = NULL;
00585 }
00586 }
00587 }
00588 }
00589 }
00590
00591
00592
00593
00594
00595
00596 }
00597
00598 void tmapgenerator::resetmapfield(void)
00599 {
00600 bar(x1 + 12,y1 + 42,x1 + 438,y1 + 388,lightgray);
00601 }
00602
00603 void tmapgenerator::run(void)
00604 {
00605 do {
00606 tdialogbox::run();
00607 if (taste == ct_f1) help(1010);
00608 } while (!((taste == ct_esc) || (action >= 2)));
00609 if (action == 2) setmap();
00610 for (int i=0;i<layercount ;i++ ) {
00611 if (initialized[i]) {
00612 asc_free(mblocks[i]->mempointer);
00613 asc_free(mblocks[i]);
00614 }
00615 }
00616 }
00617
00618
00619 void tmapgenerator::buttonpressed(int id)
00620 {
00621
00622 switch (id ) {
00623 case 1: {
00624 if (initialized[layer] == false ) {
00625 plasma.creatememblock();
00626 mblocks[layer] = plasma.memblock;
00627 initialized[layer] = true;
00628 switch (layer) {
00629 case clland : {
00630 plasma.memblock->color[0] = cverydeepwater;
00631 plasma.memblock->color[1] = cdeepwater;
00632 plasma.memblock->color[2] = cwater;
00633 plasma.memblock->color[3] = cshallowwater;
00634 plasma.memblock->color[4] = cland;
00635 plasma.memblock->color[5] = cmount;
00636 plasma.memblock->tilevalcount = 5;
00637 strcpy(plasma.memblock->bordername[0],"Deep-water");
00638 strcpy(plasma.memblock->bordername[1],"Medium-water");
00639 strcpy(plasma.memblock->bordername[2],"Shallow-water");
00640 strcpy(plasma.memblock->bordername[3],"Land");
00641 strcpy(plasma.memblock->bordername[4],"Mountain");
00642 showland=true;
00643 addbutton("~M~ap",10,397,50,405,3,1,21,true);
00644 addeingabe(21,&showland,0,lightgray);
00645 enablebutton(21);
00646 barsize = maxbarsize;
00647 }
00648 break;
00649 case clforest : {
00650 plasma.memblock->color[0] = cland;
00651 plasma.memblock->color[1] = cforest;
00652 plasma.memblock->tilevalcount = 1;
00653 strcpy(plasma.memblock->bordername[0],"Forest");
00654 showforest = true;
00655 addbutton("~F~orest",60,397,120,405,3,1,22,true);
00656 addeingabe(22,&showforest,0,lightgray);
00657 enablebutton(22);
00658 }
00659 break;
00660 case cldesert : {
00661 plasma.memblock->color[0] = cland;
00662 plasma.memblock->color[1] = cdesert;
00663 plasma.memblock->tilevalcount = 1;
00664 strcpy(plasma.memblock->bordername[0],"Desert");
00665 showdesert=true;
00666 addbutton("~D~esert",130,397,190,405,3,1,23,true);
00667 addeingabe(23,&showdesert,0,lightgray);
00668 enablebutton(23);
00669 }
00670 break;
00671 case clmaterial: {
00672 plasma.memblock->color[0] = ctransparent;
00673 plasma.memblock->color[1] = cfewmaterial;
00674 plasma.memblock->color[2] = cmediummaterial;
00675 plasma.memblock->color[3] = cmuchmaterial;
00676 plasma.memblock->tilevalcount = 3;
00677 strcpy(plasma.memblock->bordername[0],"Few Material");
00678 strcpy(plasma.memblock->bordername[1],"Medium Material");
00679 strcpy(plasma.memblock->bordername[2],"Much Material");
00680 showmaterial=true;
00681 addbutton("~M~aterial",200,397,260,405,3,1,24,true);
00682 addeingabe(24,&showmaterial,0,lightgray);
00683 enablebutton(24);
00684 }
00685 break;
00686 case clfuel: {
00687 plasma.memblock->color[0] = ctransparent;
00688 plasma.memblock->color[1] = cfewfuel;
00689 plasma.memblock->color[2] = cmediumfuel;
00690 plasma.memblock->color[3] = cmuchfuel;
00691 plasma.memblock->tilevalcount = 3;
00692 strcpy(plasma.memblock->bordername[0],"Few Fuel");
00693 strcpy(plasma.memblock->bordername[1],"Medium Fuel");
00694 strcpy(plasma.memblock->bordername[2],"Much Fuel");
00695 showfuel=true;
00696 addbutton("~F~uel",270,397,330,405,3,1,25,true);
00697 addeingabe(25,&showfuel,0,lightgray);
00698 enablebutton(25);
00699 }
00700 break;
00701 }
00702
00703 plasma.memblock->actpres = 0;
00704 activefontsettings.font = schriften.smallarial;
00705 activefontsettings.color = red;
00706 activefontsettings.background = lightgray;
00707 activefontsettings.length = 70;
00708 bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
00709 showtext2(plasma.memblock->bordername[plasma.memblock->acttile],x1+505,y1+267);
00710 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00711 enablebutton(2);
00712 }
00713 plasma.memblock->maxset = pres;
00714 plasma.memblock->res = res;
00715 if (plasma.memblock->actpres != pres ) {
00716 plasma.generateplasma(true);
00717 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00718 enablebutton(2);
00719 addeingabe(2,&tileval,0,pres);
00720 }
00721 else plasma.generateplasma(false);
00722 plasma.memblock->actpres = pres;
00723 showmap();
00724 }
00725 break;
00726 case 2 : if (initialized[layer] == true ) {
00727 plasma.memblock->tileval[plasma.memblock->acttile] = tileval;
00728 int i;
00729 if (correctvalues == true ) {
00730 for (i=0 ;i < plasma.memblock->acttile ;i++) {
00731 if (plasma.memblock->tileval[i]>plasma.memblock->tileval[plasma.memblock->acttile])
00732 plasma.memblock->tileval[i] = plasma.memblock->tileval[plasma.memblock->acttile];
00733 }
00734 for (i=plasma.memblock->acttile+1;i < plasma.memblock->tilevalcount;i++ ) {
00735 if (plasma.memblock->tileval[i]<plasma.memblock->tileval[plasma.memblock->acttile])
00736 plasma.memblock->tileval[i] = plasma.memblock->tileval[plasma.memblock->acttile];
00737 }
00738 }
00739 if ( (calculatevalues == true ) && (plasma.memblock->acttile < plasma.memblock->tilevalcount) ) {
00740 int div =plasma.memblock->maxset - plasma.memblock->tileval[plasma.memblock->acttile];
00741 int count = plasma.memblock->tilevalcount - plasma.memblock->acttile;
00742 int add = div / count;
00743 if (add > 0) {
00744 for (i=plasma.memblock->acttile+1;i < plasma.memblock->tilevalcount;i++ ) {
00745 plasma.memblock->tileval[i] = plasma.memblock->tileval[plasma.memblock->acttile] + add * ( i - plasma.memblock->acttile);
00746 }
00747 }
00748 }
00749 showmap();
00750 }
00751 break;
00752 case 6 : if (initialized[layer] == true ){
00753 tileval++;
00754 enablebutton(2);
00755 plasma.memblock->tileval[plasma.memblock->acttile] = tileval;
00756 showmap();
00757 }
00758 break;
00759 case 5 : if (initialized[layer] == true ){
00760 tileval--;
00761 enablebutton(2);
00762 plasma.memblock->tileval[plasma.memblock->acttile] = tileval;
00763 showmap();
00764 }
00765 break;
00766 case 11 :
00767 case 12 : if ( (initialized[layer] == true ) && ( plasma.memblock->tilevalcount >1 ) ) {
00768 if (id == 11) {
00769 if (plasma.memblock->acttile > 0) plasma.memblock->acttile--;
00770 else plasma.memblock->acttile = plasma.memblock->tilevalcount -1;
00771 } else {
00772 if (plasma.memblock->acttile < plasma.memblock->tilevalcount -1 ) plasma.memblock->acttile++;
00773 else plasma.memblock->acttile = 0;
00774 }
00775 activefontsettings.font = schriften.smallarial;
00776 activefontsettings.color = red;
00777 activefontsettings.background = lightgray;
00778 activefontsettings.length = 70;
00779 bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
00780 showtext2(plasma.memblock->bordername[plasma.memblock->acttile],x1+505,y1+267);
00781 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00782 enablebutton(2);
00783 }
00784 break;
00785 case 7 :
00786 case 8 : {
00787 if (id == 7) {
00788 if (layer > 0) layer--;
00789 else layer = layercount -1;
00790 } else {
00791 if (layer < layercount -1 ) layer++;
00792 else layer = 0;
00793 }
00794 plasma.memblock = mblocks[layer];
00795 activefontsettings.font = schriften.smallarial;
00796 activefontsettings.color = red;
00797 activefontsettings.background = lightgray;
00798 activefontsettings.length = 70;
00799 bar(x1 + 501,y1 + 51,x1 + 579,y1 + 69,lightgray);
00800 showtext2(clayer[layer],x1+505,y1+52);
00801
00802 bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
00803
00804 if (initialized[layer] == true ) {
00805 pres = plasma.memblock->maxset;
00806 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00807 res = plasma.memblock->res;
00808 addeingabe(2,&tileval,0,pres);
00809 enablebutton(2);
00810 enablebutton(3);
00811 enablebutton(4);
00812
00813 plasma.memblock->actpres = 0;
00814 activefontsettings.font = schriften.smallarial;
00815 activefontsettings.color = red;
00816 activefontsettings.background = lightgray;
00817 activefontsettings.length = 70;
00818 showtext2(plasma.memblock->bordername[plasma.memblock->acttile],x1+505,y1+267);
00819 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00820 enablebutton(2);
00821 }
00822 }
00823 break;
00824 case 9 : if (initialized[layer] == true ){
00825 plasma.flip = flip;
00826 showmap();
00827 }
00828 break;
00829 case 13 :
00830 case 14 :
00831 case 15 :
00832 case 16 :
00833 case 17 : if (id -12 != barsize ) {
00834 barsize = id -12;
00835 resetmapfield();
00836 showmontlayer(centerlayer,centerlayer,barsize);
00837 }
00838 break;
00839 case 21 :
00840 case 22 :
00841 case 23 :
00842 case 24 :
00843 case 25 : {
00844 resetmapfield();
00845 showmap();
00846 }
00847 break;
00848 case 19: action = 2;
00849 break;
00850 case 20: action = 3;
00851 break;
00852 }
00853
00854
00855 }
00856
00857 int mapgenerator(void)
00858 {
00859 tmapgenerator mg;
00860
00861 mg.init();
00862 mg.run();
00863 mg.done();
00864 return 0;
00865 }
00866
00867 int random2( int max)
00868 {
00869 if (max <= 1 ) return 0;
00870 int div = RAND_MAX;
00871 div /= (max -1);
00872 int r = rand();
00873 return r / (div + 1);
00874 }
00875
00876 tplasma::tplasma(void)
00877 {
00878 maxvalue=300;
00879 maxx = 200;
00880 maxy = 150;
00881 flip=false;
00882 xsymm = 0;
00883 ysymm = 0;
00884
00885 }
00886
00887 int tplasma::creatememblock(void)
00888 {
00889 memblock = new (tmemoryblock);
00890 memblock->startblocksize = 30000;
00891 memblock->res = 4;
00892 memblock->generated = false;
00893 memblock->color[0] = 0;
00894 memblock->color[1] = 1;
00895 memblock->color[2] = 2;
00896 memblock->maxset = maxvalue;
00897 memblock->acttile = 0;
00898 memblock->tilevalcount = 2;
00899
00900 blockcount = maxx * maxy;
00901
00902 memblock->mempointer = new int[ blockcount ];
00903 return 0;
00904 }
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950