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 #include "spfst-legacy.h"
00032
00033 #define layercount 5
00034 #define centerlayer 65000
00035 #define maxoverwrite 5
00036
00037 class tmapgenerator : public tdialogbox {
00038 public :
00039 int action;
00040 void init(void);
00041 void showmap(void);
00042 void generatefinishmap(void);
00043 void montlayer(int layer);
00044 void showmontlayer( int sx, int sy, int barsize);
00045 void setpfield(int number);
00046 void setmaterial(int number);
00047 void setfuel(int number);
00048 void resetmapfield(void);
00049 void addcoast(void);
00050 void setmap(void);
00051 char checkland(int x, int y);
00052 virtual void run(void);
00053 virtual void buttonpressed(int id);
00054 protected :
00055 char flip,showland,showdesert,showforest,showmaterial,showfuel,correctvalues,calculatevalues;
00056 char initialized[ layercount ];
00057 char *constructionlayer;
00058 int layer,actlayer;
00059 int barsize,maxbarsize;
00060 int whereland;
00061 int tileval,res,pres,overwritecolorcount;
00062 tplasma plasma;
00063 pmemoryblock mblocks[ layercount ];
00064 pterraintype btyp[numofbdts];
00065 int overwritecolor[maxoverwrite];
00066 MapField* pf;
00067 };
00068
00069 const char* clayer[layercount] = {"Land", "Forest", "Desert","Material","Fuel"};
00070
00071
00072 void tmapgenerator::init(void)
00073 {
00074 int w;
00075 char s1[100],s2[100];
00076
00077 tdialogbox::init();
00078 action = 0;
00079 title = "Map generator";
00080 x1 = 10;
00081 xsize = 620;
00082 y1 = 10;
00083 ysize = 460;
00084
00085 w = (xsize - 160) / 2;
00086 windowstyle = windowstyle ^ dlg_in3d;
00087
00088 for (int i=0;i < layercount ;i++ ) initialized[i] =false;
00089
00090 plasma.maxx = actmap->xsize * 2;
00091 plasma.maxy = actmap->ysize;
00092 flip = plasma.flip;
00093 res = 10;
00094 if (res > plasma.maxx / 5) res = plasma.maxx / 5;
00095 pres = 300;
00096 tileval = 0;
00097 actlayer = layer = 0;
00098
00099
00100 int xmax = 430 / plasma.maxx;
00101 int ymax = 340 / plasma.maxy;
00102
00103 if (xmax > ymax ) maxbarsize = ymax;
00104 else maxbarsize = xmax;
00105
00106 barsize = maxbarsize;
00107
00108 constructionlayer = new ( char[plasma.maxx * plasma.maxy ]);
00109
00110 addbutton("",480,80,510,100,0,1,7,true);
00111 addkey(7,ct_down);
00112 addbutton("",530,80,560,100,0,1,8,true);
00113 addkey(8,ct_up);
00114
00115 addbutton("~G~enerate new",460,115,580,135,0,1,1,true);
00116
00117 addbutton("~R~esolution",460,155,580,175,2,1,3,true);
00118 addeingabe(3,&res,1,plasma.maxx / 5);
00119
00120 addbutton("~P~recission",460,195,580,215,2,1,4,true);
00121 addeingabe(4,&pres,0,30000);
00122
00123 addbutton("~F~lip map",480,225,580,240,3,1,9,true);
00124 addeingabe(9,&flip,0,lightgray);
00125
00126 addbutton("",460,295,580,315,2,1,2,true);
00127 addeingabe(2,&tileval,0,pres);
00128
00129 addbutton("-",480,330,510,350,0,1,5,true);
00130 addkey(5,ct_minus);
00131 addbutton("+",530,330,560,350,0,1,6,true);
00132 addkey(6,ct_plus);
00133
00134 addbutton("",480,370,510,390,0,1,11,true);
00135 addkey(11,ct_left);
00136 addbutton("",530,370,560,390,0,1,12,true);
00137 addkey(12,ct_right);
00138
00139 correctvalues = true;
00140 addbutton("Co~r~rect",520,410,600,420,3,1,50,true);
00141 addeingabe(50,&correctvalues,0,lightgray);
00142
00143 calculatevalues = true;
00144 addbutton("Ca~l~culate",520,430,600,440,3,1,51,true);
00145 addeingabe(51,&calculatevalues,0,lightgray);
00146
00147 if ( maxbarsize >=1 ) addbutton("1",345,395,360,410,0,1,13,true);
00148 addkey(13,ct_1);
00149 if ( maxbarsize >=2 ) addbutton("2",365,395,380,410,0,1,14,true);
00150 addkey(14,ct_2);
00151 if ( maxbarsize >=3 ) addbutton("3",385,395,400,410,0,1,15,true);
00152 addkey(15,ct_3);
00153 if ( maxbarsize >=4 ) addbutton("4",405,395,420,410,0,1,16,true);
00154 addkey(16,ct_4);
00155 if ( maxbarsize >=5 ) addbutton("5",425,395,440,410,0,1,17,true);
00156 addkey(17,ct_5);
00157
00158 addbutton ("~x~sym", 455,20,500,30, 3, 0, 31, true );
00159 addeingabe ( 31, &plasma.xsymm, 0, lightgray );
00160
00161 addbutton ("~y~sym", 510,20,560,30, 3, 0, 32, true );
00162 addeingabe ( 32, &plasma.ysymm, 0, lightgray );
00163
00164 addbutton("~A~ccept Map",20,ysize - 40,20 + w,ysize - 10,0,1,19,true);
00165 addbutton("~C~ancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,20,true);
00166
00167 buildgraphics();
00168
00169 activefontsettings.font = schriften.smallarial;
00170 activefontsettings.color = red;
00171 activefontsettings.background = lightgray;
00172 activefontsettings.length = 70;
00173 activefontsettings.justify = lefttext;
00174
00175 showtext2("Layer",x1+460,y1+52);
00176 rahmen(true,x1 + 500,y1 + 50,x1 + 580,y1 + 70);
00177 showtext2(clayer[layer],x1+505,y1+52);
00178
00179 showtext2("Limit",x1+460,y1+267);
00180 rahmen(true,x1 + 500,y1 + 265,x1 + 580,y1 + 285);
00181
00182 strcpy(s1,"XSize : ");
00183 strcpy(s2,"YSize : ");
00184 showtext2(strcat(s1,strrr(plasma.maxx)),x1+10,y1+10);
00185 showtext2(strcat(s2,strrr(plasma.maxy)),x1+120,y1+10);
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 rahmen(true,x1 + 450,y1 + 40,x1 + 590,y1 + 400);
00196 rahmen(true,x1 + 10,y1 + 40,x1 + 440,y1 + 390);
00197
00198
00199
00200
00201
00202
00203 mousevisible(true);
00204 }
00205
00206
00207 void tmapgenerator::montlayer(int layer)
00208 {
00209 int i,j;
00210 char found;
00211
00212 if ( overwritecolorcount == 0 ){
00213 for (i=0;i<plasma.blockcount;i++ ) {
00214 found = false;
00215 j=0;
00216 do {
00217 if (mblocks[layer]->mempointer[i] <= mblocks[layer]->tileval[j] ) {
00218 if ( mblocks[layer]->color[j] != ctransparent ) constructionlayer[i] = mblocks[layer]->color[j];
00219 found = true;
00220 }
00221 else j++;
00222 } while ( ( found == false ) && (j < mblocks[layer]->tilevalcount ) );
00223 if ( (j == mblocks[layer]->tilevalcount ) && ( mblocks[layer]->color[int(mblocks[layer]->tilevalcount)] != ctransparent ) )
00224 constructionlayer[i] = mblocks[layer]->color[int(mblocks[layer]->tilevalcount)];
00225 }
00226 } else {
00227 for (i=0;i<plasma.blockcount;i++ ) {
00228 for (int k=0;k<overwritecolorcount;k++ ) {
00229 if (constructionlayer[i] == overwritecolor[k]) {
00230 found = false;
00231 j=0;
00232 do {
00233 if (mblocks[layer]->mempointer[i] <= mblocks[layer]->tileval[j] ) {
00234 constructionlayer[i] = mblocks[layer]->color[j];
00235 found = true;
00236 }
00237 else j++;
00238 } while ( ( found == false ) && (j < mblocks[layer]->tilevalcount ) );
00239 if (j == mblocks[layer]->tilevalcount )
00240 constructionlayer[i] = mblocks[layer]->color[int(mblocks[layer]->tilevalcount)];
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
00275 void tmapgenerator::showmontlayer(int sx, int sy, int barsize)
00276 {
00277 int i;
00278
00279 int prevx,prevy;
00280
00281
00282
00283
00284 prevx = x1 + 15 + (430 - plasma.maxx * barsize ) / 2;
00285 prevy = y1 + 45 + (340 - plasma.maxy * barsize ) / 2;
00286
00287 if (sx == centerlayer) sx = prevx;
00288 if (sy == centerlayer) sy = prevy;
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
00317 int x,y;
00318
00319 x = sx;
00320 y = sy;
00321
00322 if (flip == true) {
00323 for (i=plasma.blockcount-1;i>=0 ;i-- ) {
00324 if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
00325 else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
00326 x += barsize;
00327 if (x >= sx + (plasma.maxx) * barsize ) {
00328 x = sx;
00329 y += barsize;
00330 }
00331 }
00332 } else {
00333 for (i=0;i<plasma.blockcount;i++ ) {
00334 if ( barsize <= 1 ) putpixel(x,y, constructionlayer[i]);
00335 else bar(x,y,x+barsize-1,y+barsize-1, constructionlayer[i]);
00336 x += barsize;
00337 if (x >= sx + (plasma.maxx) * barsize ) {
00338 x = sx;
00339 y += barsize;
00340 }
00341 }
00342 }
00343 }
00344
00345 void tmapgenerator::generatefinishmap(void)
00346 {
00347 overwritecolorcount = 0;
00348 if ( (showland == true ) && (initialized[0] == true ) ) montlayer(0);
00349 else memset(constructionlayer,lightgray,plasma.blockcount);
00350
00351 overwritecolorcount = 2;
00352 overwritecolor[0] = mblocks[clland]->color[4];
00353 overwritecolor[1] = lightgray;
00354 if ( (showforest == true ) && (initialized[1] == true ) ) montlayer(1);
00355
00356 overwritecolorcount = 2;
00357 overwritecolor[0] = mblocks[clland]->color[4];
00358 overwritecolor[1] = lightgray;
00359 if ( (showdesert == true ) && (initialized[2] == true ) ) montlayer(2);
00360 }
00361
00362
00363
00364
00365
00366
00367
00368 void tmapgenerator::showmap(void)
00369 {
00370 generatefinishmap();
00371
00372 overwritecolorcount = 0;
00373 if ( (showmaterial == true ) && (initialized[3] == true ) ) montlayer(3);
00374
00375 overwritecolorcount = 0;
00376 if ( (showfuel == true ) && (initialized[4] == true ) ) montlayer(4);
00377
00378 showmontlayer(centerlayer,centerlayer,barsize);
00379 }
00380
00381 char tmapgenerator::checkland(int x, int y)
00382 {
00383 if ( ( getfield(x,y)->typ->art & getTerrainBitType(cbwater) ).none() )
00384 return true;
00385 else
00386 return false;
00387 }
00388
00389 void tmapgenerator::addcoast(void)
00390 {
00391 MapField* pf;
00392 const int id[2]={42,83};
00393
00394 for (int i=0;i<2;i++ ) {
00395 if (id[i] != 0 ) {
00396 btyp[i] = terrainTypeRepository.getObject_byID(id[i]);
00397 if (btyp[i] == NULL) btyp[i] = terrainTypeRepository.getObject_byPos(0);
00398 }
00399 }
00400
00401
00402
00403 for (int y=0;y<actmap->ysize ;y++ ) {
00404 for (int x=0;x<actmap->xsize ;x++) {
00405 pf = getfield(x,y);
00406 whereland = 0;
00407 if ( checkland(x,y) == false ){
00408 if ( (x >1 ) && (y >1 ) && (y < actmap->ysize-2 ) && ( x < actmap->xsize -2) ){
00409 if ( checkland(x+1, y) ) whereland |= 4;
00410 if ( checkland(x-1, y) ) whereland |= 64;
00411 if ( checkland(x, y+2) ) whereland |= 16;
00412 if ( checkland(x, y-2) ) whereland |= 1;
00413 if (y & 1) {
00414 if ( checkland(x-1, y-1) ) whereland |= 128;
00415 if ( checkland(x, y-1) ) whereland |= 2;
00416 if ( checkland(x, y+1) ) whereland |= 8;
00417 if ( checkland(x-1, y+1) ) whereland |= 32;
00418 } else {
00419 if ( checkland(x, y-1) ) whereland |= 128;
00420 if ( checkland(x+1,y-1) ) whereland |= 2;
00421 if ( checkland(x+1, y+1) ) whereland |= 8;
00422 if ( checkland(x, y+1) ) whereland |= 32;
00423 }
00424 if (whereland & 1) {
00425 pf->typ = btyp[0]->weather[0];
00426
00427 }
00428 if (whereland & 2) {
00429 pf->typ = btyp[1]->weather[0];
00430
00431 }
00432 if (whereland & 4) {
00433 pf->typ = btyp[0]->weather[0];
00434
00435 }
00436 if (whereland & 8) {
00437 pf->typ = btyp[1]->weather[0];
00438
00439 }
00440 if (whereland & 16) {
00441 pf->typ = btyp[0]->weather[0];
00442
00443 }
00444 if (whereland & 32) {
00445 pf->typ = btyp[1]->weather[0];
00446
00447 }
00448 if (whereland & 64) {
00449 pf->typ = btyp[0]->weather[0];
00450
00451 }
00452 if (whereland & 128) {
00453 pf->typ = btyp[1]->weather[0];
00454
00455 }
00456 }
00457 }
00458 }
00459 }
00460 }
00461
00462 void tmapgenerator::setpfield(int number)
00463 {
00464 switch ( constructionlayer[ number ] ) {
00465 case cwater : pf->typ = btyp[0]->weather[0];
00466 break;
00467 case cland : pf->typ = btyp[1]->weather[0];
00468 break;
00469 case cmount : pf->typ = btyp[2]->weather[0];
00470 break;
00471 case cforest : pf->typ = btyp[3]->weather[0];
00472 break;
00473 case cdesert : pf->typ = btyp[4]->weather[0];
00474 break;
00475 case cshallowwater : pf->typ = btyp[5]->weather[0];
00476 break;
00477 case cdeepwater : pf->typ = btyp[6]->weather[0];
00478 break;
00479 case cverydeepwater : pf->typ = btyp[7]->weather[0];
00480 break;
00481 default: pf->typ = btyp[1]->weather[0];
00482 break;
00483 }
00484 }
00485
00486 int matdiv[3];
00487 int fueldiv[3];
00488
00489 #define enhance 1000
00490
00491 void tmapgenerator::setmaterial(int number)
00492 {
00493 for (int i =mblocks[clmaterial]->tilevalcount-1;i >=0 ;i-- ) {
00494 if (mblocks[clmaterial]->mempointer[number] > mblocks[clmaterial]->tileval[i] ) {
00495 int test = ( ( (mblocks[clmaterial]->mempointer[number] - mblocks[clmaterial]->tileval[i] ) * matdiv[i] / enhance ) + (i * 80)) * 14 / 10;
00496 if ( test > 255 ) pf->material = 255;
00497 else pf->material = test;
00498 return;
00499 }
00500 }
00501 }
00502
00503 void tmapgenerator::setfuel(int number)
00504 {
00505 for (int i =mblocks[clfuel]->tilevalcount-1;i >=0 ;i-- ) {
00506 if (mblocks[clfuel]->mempointer[number] > mblocks[clfuel]->tileval[i] ){
00507 int test = ( ( (mblocks[clfuel]->mempointer[number] - mblocks[clfuel]->tileval[i] ) * fueldiv[i] / enhance ) + (i * 80) ) * 14 / 10;
00508 if ( test>255 ) pf->fuel =255;
00509 else pf->fuel = test;
00510 return;
00511 }
00512 }
00513 }
00514
00515
00516 int terrain_object_ids[numofbdts][2][2] = {{{ 299, -1 }, { 307, -1 }},
00517 {{ 28 , -1 }, { 38 , -1 }},
00518 {{ 30 , -1 }, { 40 , -1 }},
00519 {{ 30 , -1 }, { 40 , -1 }},
00520 {{ 34 , -1 }, { 35 , -1 }},
00521 {{ 299, -1 }, { 307, -1 }},
00522 {{ 301, -1 }, { 308, -1 }},
00523 {{ 302, -1 }, { 309, -1 }},
00524 {{ 30 , -1 }, { 40 , -1 }},
00525 {{ 30 , -1 }, { 40 , -1 }},
00526 {{ 30 , -1 }, { 40 , -1 }},
00527 {{ 30 , -1 }, { 40 , -1 }}};
00528
00529 void tmapgenerator::setmap(void)
00530 {
00531
00532 int i,j;
00533
00534 generatefinishmap();
00535
00536 int set = 2 - choice_dlg("Choose terrain set","dark","light") ;
00537 for (i=0;i<numofbdts ;i++ ) {
00538 btyp[i] = terrainTypeRepository.getObject_byID( terrain_object_ids[i][set][0] );
00539 if ( !btyp[i] )
00540 btyp[i] = terrainTypeRepository.getObject_byPos(0);
00541 }
00542
00543 if (initialized[clmaterial] == true ) {
00544 matdiv[0] = 81 * enhance / ( mblocks[clmaterial]->tileval[1] -mblocks[clmaterial]->tileval[0] +1 ) ;
00545 matdiv[1] = 80 * enhance / ( mblocks[clmaterial]->tileval[2] - mblocks[clmaterial]->tileval[1] +1 );
00546 matdiv[2] = 95 * enhance / ( mblocks[clmaterial]->actpres - mblocks[clmaterial]->tileval[1] +1);
00547 }
00548
00549 if (initialized[clfuel] == true ) {
00550 fueldiv[0] = 81 * enhance / ( mblocks[clfuel]->tileval[1] -mblocks[clfuel]->tileval[0] +1);
00551 fueldiv[1] = 80 * enhance / ( mblocks[clfuel]->tileval[2] - mblocks[clfuel]->tileval[1] +1);
00552 fueldiv[2] = 95 * enhance / ( mblocks[clfuel]->actpres - mblocks[clfuel]->tileval[1] +1);
00553 }
00554
00555 if ( ( actmap->xsize * 2 == plasma.maxx ) && (actmap->ysize == plasma.maxy ) ){
00556 mapsaved = false;
00557 if (flip == true) {
00558 for (i=0;i< ( plasma.maxx / 2 ) ;i++ ) {
00559 for (j=0;j<plasma.maxy;j++ ) {
00560 pf = &actmap->field[ ( plasma.maxx / 2 - i - 1 ) + ( ( plasma.maxy - j -1) * plasma.maxx / 2 ) ];
00561 int plasmalayernr = ( i * 2 + ( j & 1 ) ) + ( j * plasma.maxx );
00562 setpfield ( plasmalayernr ) ;
00563 pf->setparams();
00564 if (initialized[clmaterial] == true ) setmaterial ( plasmalayernr );
00565 if (initialized[clfuel] ==true ) setfuel ( plasmalayernr );
00566 if ( pf->vehicle )
00567 if ( terrainaccessible(pf,pf->vehicle) == false ) {
00568 delete pf->vehicle;
00569 pf->vehicle = NULL;
00570 }
00571 }
00572 }
00573 } else {
00574 for (i=0;i< ( plasma.maxx / 2 ) ;i++ ) {
00575 for (j=0;j<plasma.maxy;j++ ) {
00576 pf = &actmap->field[i + ( j * plasma.maxx / 2 ) ];
00577 int plasmalayernr = ( i * 2 + ( j & 1 ) ) + ( j * plasma.maxx );
00578 setpfield ( plasmalayernr ) ;
00579 pf->setparams();
00580 if (initialized[clmaterial] == true ) setmaterial ( plasmalayernr );
00581 if (initialized[clfuel] ==true ) setfuel ( plasmalayernr );
00582 if ( pf->vehicle )
00583 if ( terrainaccessible(pf,pf->vehicle) == false ) {
00584 delete pf->vehicle;
00585 pf->vehicle = NULL;
00586 }
00587 }
00588 }
00589 }
00590 }
00591
00592
00593
00594
00595
00596
00597 }
00598
00599 void tmapgenerator::resetmapfield(void)
00600 {
00601 bar(x1 + 12,y1 + 42,x1 + 438,y1 + 388,lightgray);
00602 }
00603
00604 void tmapgenerator::run(void)
00605 {
00606 do {
00607 tdialogbox::run();
00608 if (taste == ct_f1) help(1010);
00609 } while (!((taste == ct_esc) || (action >= 2)));
00610 if (action == 2) setmap();
00611 for (int i=0;i<layercount ;i++ ) {
00612 if (initialized[i]) {
00613 free(mblocks[i]->mempointer);
00614 free(mblocks[i]);
00615 }
00616 }
00617 }
00618
00619
00620 void tmapgenerator::buttonpressed(int id)
00621 {
00622
00623 switch (id ) {
00624 case 1: {
00625 if (initialized[layer] == false ) {
00626 plasma.creatememblock();
00627 mblocks[layer] = plasma.memblock;
00628 initialized[layer] = true;
00629 switch (layer) {
00630 case clland : {
00631 plasma.memblock->color[0] = cverydeepwater;
00632 plasma.memblock->color[1] = cdeepwater;
00633 plasma.memblock->color[2] = cwater;
00634 plasma.memblock->color[3] = cshallowwater;
00635 plasma.memblock->color[4] = cland;
00636 plasma.memblock->color[5] = cmount;
00637 plasma.memblock->tilevalcount = 5;
00638 strcpy(plasma.memblock->bordername[0],"Deep-water");
00639 strcpy(plasma.memblock->bordername[1],"Medium-water");
00640 strcpy(plasma.memblock->bordername[2],"Shallow-water");
00641 strcpy(plasma.memblock->bordername[3],"Land");
00642 strcpy(plasma.memblock->bordername[4],"Mountain");
00643 showland=true;
00644 addbutton("~M~ap",10,397,50,405,3,1,21,true);
00645 addeingabe(21,&showland,0,lightgray);
00646 enablebutton(21);
00647 barsize = maxbarsize;
00648 }
00649 break;
00650 case clforest : {
00651 plasma.memblock->color[0] = cland;
00652 plasma.memblock->color[1] = cforest;
00653 plasma.memblock->tilevalcount = 1;
00654 strcpy(plasma.memblock->bordername[0],"Forest");
00655 showforest = true;
00656 addbutton("~F~orest",60,397,120,405,3,1,22,true);
00657 addeingabe(22,&showforest,0,lightgray);
00658 enablebutton(22);
00659 }
00660 break;
00661 case cldesert : {
00662 plasma.memblock->color[0] = cland;
00663 plasma.memblock->color[1] = cdesert;
00664 plasma.memblock->tilevalcount = 1;
00665 strcpy(plasma.memblock->bordername[0],"Desert");
00666 showdesert=true;
00667 addbutton("~D~esert",130,397,190,405,3,1,23,true);
00668 addeingabe(23,&showdesert,0,lightgray);
00669 enablebutton(23);
00670 }
00671 break;
00672 case clmaterial: {
00673 plasma.memblock->color[0] = ctransparent;
00674 plasma.memblock->color[1] = cfewmaterial;
00675 plasma.memblock->color[2] = cmediummaterial;
00676 plasma.memblock->color[3] = cmuchmaterial;
00677 plasma.memblock->tilevalcount = 3;
00678 strcpy(plasma.memblock->bordername[0],"Few Material");
00679 strcpy(plasma.memblock->bordername[1],"Medium Material");
00680 strcpy(plasma.memblock->bordername[2],"Much Material");
00681 showmaterial=true;
00682 addbutton("~M~aterial",200,397,260,405,3,1,24,true);
00683 addeingabe(24,&showmaterial,0,lightgray);
00684 enablebutton(24);
00685 }
00686 break;
00687 case clfuel: {
00688 plasma.memblock->color[0] = ctransparent;
00689 plasma.memblock->color[1] = cfewfuel;
00690 plasma.memblock->color[2] = cmediumfuel;
00691 plasma.memblock->color[3] = cmuchfuel;
00692 plasma.memblock->tilevalcount = 3;
00693 strcpy(plasma.memblock->bordername[0],"Few Fuel");
00694 strcpy(plasma.memblock->bordername[1],"Medium Fuel");
00695 strcpy(plasma.memblock->bordername[2],"Much Fuel");
00696 showfuel=true;
00697 addbutton("~F~uel",270,397,330,405,3,1,25,true);
00698 addeingabe(25,&showfuel,0,lightgray);
00699 enablebutton(25);
00700 }
00701 break;
00702 }
00703
00704 plasma.memblock->actpres = 0;
00705 activefontsettings.font = schriften.smallarial;
00706 activefontsettings.color = red;
00707 activefontsettings.background = lightgray;
00708 activefontsettings.length = 70;
00709 bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
00710 showtext2(plasma.memblock->bordername[plasma.memblock->acttile],x1+505,y1+267);
00711 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00712 enablebutton(2);
00713 }
00714 plasma.memblock->maxset = pres;
00715 plasma.memblock->res = res;
00716 if (plasma.memblock->actpres != pres ) {
00717 plasma.generateplasma(true);
00718 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00719 enablebutton(2);
00720 addeingabe(2,&tileval,0,pres);
00721 }
00722 else plasma.generateplasma(false);
00723 plasma.memblock->actpres = pres;
00724 showmap();
00725 }
00726 break;
00727 case 2 : if (initialized[layer] == true ) {
00728 plasma.memblock->tileval[plasma.memblock->acttile] = tileval;
00729 int i;
00730 if (correctvalues == true ) {
00731 for (i=0 ;i < plasma.memblock->acttile ;i++) {
00732 if (plasma.memblock->tileval[i]>plasma.memblock->tileval[plasma.memblock->acttile])
00733 plasma.memblock->tileval[i] = plasma.memblock->tileval[plasma.memblock->acttile];
00734 }
00735 for (i=plasma.memblock->acttile+1;i < plasma.memblock->tilevalcount;i++ ) {
00736 if (plasma.memblock->tileval[i]<plasma.memblock->tileval[plasma.memblock->acttile])
00737 plasma.memblock->tileval[i] = plasma.memblock->tileval[plasma.memblock->acttile];
00738 }
00739 }
00740 if ( (calculatevalues == true ) && (plasma.memblock->acttile < plasma.memblock->tilevalcount) ) {
00741 int div =plasma.memblock->maxset - plasma.memblock->tileval[plasma.memblock->acttile];
00742 int count = plasma.memblock->tilevalcount - plasma.memblock->acttile;
00743 int add = div / count;
00744 if (add > 0) {
00745 for (i=plasma.memblock->acttile+1;i < plasma.memblock->tilevalcount;i++ ) {
00746 plasma.memblock->tileval[i] = plasma.memblock->tileval[plasma.memblock->acttile] + add * ( i - plasma.memblock->acttile);
00747 }
00748 }
00749 }
00750 showmap();
00751 }
00752 break;
00753 case 6 : if (initialized[layer] == true ){
00754 tileval++;
00755 enablebutton(2);
00756 plasma.memblock->tileval[plasma.memblock->acttile] = tileval;
00757 showmap();
00758 }
00759 break;
00760 case 5 : if (initialized[layer] == true ){
00761 tileval--;
00762 enablebutton(2);
00763 plasma.memblock->tileval[plasma.memblock->acttile] = tileval;
00764 showmap();
00765 }
00766 break;
00767 case 11 :
00768 case 12 : if ( (initialized[layer] == true ) && ( plasma.memblock->tilevalcount >1 ) ) {
00769 if (id == 11) {
00770 if (plasma.memblock->acttile > 0) plasma.memblock->acttile--;
00771 else plasma.memblock->acttile = plasma.memblock->tilevalcount -1;
00772 } else {
00773 if (plasma.memblock->acttile < plasma.memblock->tilevalcount -1 ) plasma.memblock->acttile++;
00774 else plasma.memblock->acttile = 0;
00775 }
00776 activefontsettings.font = schriften.smallarial;
00777 activefontsettings.color = red;
00778 activefontsettings.background = lightgray;
00779 activefontsettings.length = 70;
00780 bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
00781 showtext2(plasma.memblock->bordername[plasma.memblock->acttile],x1+505,y1+267);
00782 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00783 enablebutton(2);
00784 }
00785 break;
00786 case 7 :
00787 case 8 : {
00788 if (id == 7) {
00789 if (layer > 0) layer--;
00790 else layer = layercount -1;
00791 } else {
00792 if (layer < layercount -1 ) layer++;
00793 else layer = 0;
00794 }
00795 plasma.memblock = mblocks[layer];
00796 activefontsettings.font = schriften.smallarial;
00797 activefontsettings.color = red;
00798 activefontsettings.background = lightgray;
00799 activefontsettings.length = 70;
00800 bar(x1 + 501,y1 + 51,x1 + 579,y1 + 69,lightgray);
00801 showtext2(clayer[layer],x1+505,y1+52);
00802
00803 bar(x1 + 501,y1 + 266,x1 + 579,y1 + 284,lightgray);
00804
00805 if (initialized[layer] == true ) {
00806 pres = plasma.memblock->maxset;
00807 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00808 res = plasma.memblock->res;
00809 addeingabe(2,&tileval,0,pres);
00810 enablebutton(2);
00811 enablebutton(3);
00812 enablebutton(4);
00813
00814 plasma.memblock->actpres = 0;
00815 activefontsettings.font = schriften.smallarial;
00816 activefontsettings.color = red;
00817 activefontsettings.background = lightgray;
00818 activefontsettings.length = 70;
00819 showtext2(plasma.memblock->bordername[plasma.memblock->acttile],x1+505,y1+267);
00820 tileval = plasma.memblock->tileval[plasma.memblock->acttile];
00821 enablebutton(2);
00822 }
00823 }
00824 break;
00825 case 9 : if (initialized[layer] == true ){
00826 plasma.flip = flip;
00827 showmap();
00828 }
00829 break;
00830 case 13 :
00831 case 14 :
00832 case 15 :
00833 case 16 :
00834 case 17 : if (id -12 != barsize ) {
00835 barsize = id -12;
00836 resetmapfield();
00837 showmontlayer(centerlayer,centerlayer,barsize);
00838 }
00839 break;
00840 case 21 :
00841 case 22 :
00842 case 23 :
00843 case 24 :
00844 case 25 : {
00845 resetmapfield();
00846 showmap();
00847 }
00848 break;
00849 case 19: action = 2;
00850 break;
00851 case 20: action = 3;
00852 break;
00853 }
00854
00855
00856 }
00857
00858 int mapgenerator(void)
00859 {
00860 tmapgenerator mg;
00861
00862 mg.init();
00863 mg.run();
00864 mg.done();
00865 return 0;
00866 }
00867
00868 int random2( int max)
00869 {
00870 if (max <= 1 ) return 0;
00871 int div = RAND_MAX;
00872 div /= (max -1);
00873 int r = rand();
00874 return r / (div + 1);
00875 }
00876
00877 tplasma::tplasma(void)
00878 {
00879 maxvalue=300;
00880 maxx = 200;
00881 maxy = 150;
00882 flip=false;
00883 xsymm = 0;
00884 ysymm = 0;
00885
00886 }
00887
00888 int tplasma::creatememblock(void)
00889 {
00890 memblock = new (tmemoryblock);
00891 memblock->startblocksize = 30000;
00892 memblock->res = 4;
00893 memblock->generated = false;
00894 memblock->color[0] = 0;
00895 memblock->color[1] = 1;
00896 memblock->color[2] = 2;
00897 memblock->maxset = maxvalue;
00898 memblock->acttile = 0;
00899 memblock->tilevalcount = 2;
00900
00901 blockcount = maxx * maxy;
00902
00903 memblock->mempointer = new int[ blockcount ];
00904 return 0;
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
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011 int tplasma::getmem(int x, int y)
01012 {
01013 if (x >= maxx ) x -= maxx;
01014 if (y >= maxy ) y -= maxy;
01015 return memblock->mempointer[ x + (y * maxx ) ] ;
01016 }
01017
01018
01019 void tplasma::setmemory(int x, int y, int color)
01020 {
01021 if (x >= maxx ) x -= maxx;
01022 if (y >= maxy ) y -= maxy;
01023 memblock->mempointer[ x + (y * maxx ) ] = color;
01024 }
01025
01026 void tplasma::membar( int x1 ,int y1 ,int x2 ,int y2, int color )
01027 { int exc;
01028 if (x1 >x2) {
01029 exc = x1;
01030 x1 = x2;
01031 x2 = exc;
01032 }
01033
01034 if (y1 >y2) {
01035 exc = y1 ;
01036 y1 = y2 ;
01037 y2 = exc ;
01038 }
01039
01040 for (int j=y1;j<=y2;j++ ) {
01041 for (int i=x1;i<=x2;i++) {
01042
01043 setmemory(i,j,color);
01044 }
01045 }
01046 }
01047
01048
01049
01050 void tplasma::generateplasma(char resettile)
01051 {
01052 int colour;
01053 int sblocksize;
01054
01055 if (memblock->startblocksize / 2 >= maxx) memblock->startblocksize = maxx / 2;
01056
01057 int blocksize = memblock->startblocksize;
01058
01059 blocksize /= memblock->res;
01060
01061 sblocksize = blocksize;
01062
01063
01064
01065
01066 memblock->generated = true;
01067
01068 if (resettile == true ) {
01069 for (int i=0;i<memblock->tilevalcount;i++ ) {
01070 memblock->tileval[i] = ( memblock->maxset / ( memblock->tilevalcount +1 ) ) * (i +1 );
01071 }
01072 } else {
01073 for (int i=0;i<memblock->tilevalcount;i++ ) {
01074 if (memblock->tileval[i] > memblock->maxset) memblock->tileval[i] = memblock->maxset;
01075 }
01076 }
01077
01078
01079
01080 int maxy_local = maxy;
01081 #ifdef cheatsymmetry
01082 maxy_local /= 2;
01083 #endif
01084
01085 do {
01086 for(register int y = 0; y < (maxy_local / blocksize) + 1; y++) {
01087 for(register int x = 0; x < (maxx / blocksize) + 1; x++) {
01088
01089
01090
01091
01092 if(blocksize == sblocksize) {
01093 colour = random2(memblock->maxset + 1);
01094 if( random2(5000) > 3500)
01095 colour = 1 + memblock->maxset - random2(memblock->maxset / (1 + random2(8)));
01096 colour %= (memblock->maxset + 1);
01097 }
01098 else {
01099 colour = getmem(x * blocksize >= maxx ? 0 : x * blocksize + blocksize,y * blocksize);
01100 colour += getmem(x * blocksize,y * blocksize < 2 * blocksize ? maxy_local : y * blocksize - blocksize);
01101 colour += getmem(x * blocksize < 2 * blocksize ? maxx : x * blocksize - blocksize,y * blocksize);
01102 colour += getmem(x * blocksize,y * blocksize > maxy_local - blocksize ? 0 : y * blocksize + blocksize);
01103
01104
01105
01106
01107
01108 colour /= 4;
01109 }
01110 if(blocksize != 1) membar(x * blocksize, y * blocksize, x * blocksize + blocksize - 1, y * blocksize + blocksize - 1,colour);
01111 else setmemory(x,y,colour);
01112
01113 }
01114 }
01115 blocksize /= 2;
01116 } while(blocksize > 0);
01117
01118
01119 if ( ysymm )
01120 for(int y = maxy/2; y < maxy; y++)
01121 for(int x = 0; x < maxx ; x++)
01122 setmemory(x , y, getmem ( x, maxy-y ));
01123
01124 if ( xsymm )
01125 for(int x = maxx/2; x < maxx ; x++)
01126 for(int y = 0; y < maxy; y++)
01127 setmemory(x , y, getmem ( maxx-x, y ));
01128
01129
01130
01131 }