00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <string>
00028 #include <iostream>
00029 #include <math.h>
00030
00031 #include "sdl/graphics.h"
00032 #include "vehicletype.h"
00033 #include "buildingtype.h"
00034 #include "edmisc.h"
00035 #include "loadbi3.h"
00036 #include "edgen.h"
00037 #include "edselfnt.h"
00038 #include "edglobal.h"
00039 #include "dialogs/pwd_dlg.h"
00040 #include "mapdisplay.h"
00041 #include "graphicset.h"
00042 #include "itemrepository.h"
00043 #include "textfileparser.h"
00044 #include "textfile_evaluation.h"
00045 #include "textfiletags.h"
00046 #include "clipboard.h"
00047 #include "dialogs/cargowidget.h"
00048 #include "dialogs/fieldmarker.h"
00049 #include "dialogs/newmap.h"
00050 #include "stack.h"
00051
00052 #include "unitset.h"
00053 #include "maped-mainscreen.h"
00054 #include "gameevents.h"
00055 #include "gameevent_dialogs.h"
00056 #include "dialogs/fileselector.h"
00057 #include "pgeventsupplier.h"
00058 #include "dialogs/edittechadapter.h"
00059 #include "spfst-legacy.h"
00060 #include "textfile_evaluation.h"
00061 #include "lua/luarunner.h"
00062 #include "lua/luastate.h"
00063 #include "widgets/multilistbox.h"
00064
00065 bool mapsaved;
00066
00067
00068
00069 void placeCurrentItem()
00070 {
00071 if ( selection.getSelection() && actmap->getCursor().valid() ) {
00072 if ( selection.getSelection()->supportMultiFieldPlacement() && selection.brushSize > 1 ) {
00073 circularFieldIterator( actmap, actmap->getCursor(), 0, selection.brushSize-1, FieldIterationFunctor( selection.getSelection(), &MapComponent::vPlace ));
00074 } else {
00075 selection.getSelection()->place( actmap->getCursor() );
00076 }
00077 mapChanged( actmap );
00078 }
00079 }
00080
00081 bool removeCurrentItem()
00082 {
00083 if ( selection.getSelection() && actmap->getCursor().valid() )
00084 return selection.getSelection()->remove( actmap->getCursor() );
00085 else
00086 return false;
00087 }
00088
00089
00090 bool mousePressedOnField( const MapCoordinate& pos, const SPoint& mousePos, bool cursorChanged, int button, int prio )
00091 {
00092 if ( prio > 1 )
00093 return false;
00094
00095 if ( button == 1 ) {
00096 execaction_ev( act_primaryAction );
00097 return true;
00098 } else
00099 return false;
00100 }
00101
00102 bool mouseDraggedToField( const MapCoordinate& pos, const SPoint& mousePos, bool cursorChanged, int prio )
00103 {
00104 if ( prio > 1 )
00105 return false;
00106 execaction_ev( act_primaryAction );
00107 return true;
00108 }
00109
00110
00111
00112
00113 char checkobject(MapField* pf)
00114 {
00115 return !pf->objects.empty();
00116 }
00117
00118
00119
00120
00121
00122 void tputresources :: init ( int sx, int sy, int dst, int restype, int resmax, int resmin )
00123 {
00124 centerPos = MapCoordinate(sx,sy);
00125 initsearch( centerPos, dst, 0);
00126 resourcetype = restype;
00127 maxresource = resmax;
00128 minresource = resmin;
00129 maxdst = dst;
00130 startsearch();
00131 }
00132
00133 void tputresources :: testfield ( const MapCoordinate& mc )
00134 {
00135 int dist = beeline ( mc, centerPos ) / 10;
00136 int m = maxresource - dist * ( maxresource - minresource ) / maxdst;
00137
00138 MapField* fld = gamemap->getField ( mc );
00139 if ( resourcetype == 1 )
00140 fld->material = min( 255, fld->material + m);
00141 else
00142 fld->fuel = min( 255, fld->fuel + m );
00143 }
00144
00145 void tputresourcesdlg :: init ( void )
00146 {
00147 resourcetype = 1;
00148 restp2 = 0;
00149 status = 0;
00150 tdialogbox::init();
00151 title = "set resources";
00152 xsize = 400;
00153 ysize = 300;
00154 maxresource = 200;
00155 minresource = 0;
00156 dist = 10;
00157
00158 addbutton ( "~O~k", 10, ysize - 30, xsize/2 - 5, ysize - 10 , 0, 1, 1, true );
00159 addkey ( 1, ct_enter );
00160 addbutton ( "~C~ancel", xsize/2 + 5, ysize - 30, xsize-10 - 5, ysize - 10 , 0, 1, 2, true );
00161 addkey ( 2, ct_esc );
00162
00163 addbutton ( "ma~x~ resources ( at center )", xsize/2 + 5, 80, xsize-20 - 5, 100 , 2, 1, 3, true );
00164 addeingabe ( 3, &maxresource, 0, 255 );
00165
00166 addbutton ( "mi~n~ resources ", xsize/2 + 5, 120, xsize-20 - 5, 140 , 2, 1, 4, true );
00167 addeingabe ( 4, &minresource, 0, 255 );
00168
00169 addbutton ( "max ~d~istance", 20, 120, xsize/2-5, 140 , 2, 1, 5, true );
00170 addeingabe ( 5, &dist, 1, 20 );
00171
00172 addbutton ( "~m~aterial", 20, 160, xsize/2-5, 180, 3, 10, 6, true );
00173 addeingabe ( 6, &resourcetype, black, dblue );
00174
00175 addbutton ( "~f~uel", xsize/2 + 5, 160, xsize - 20, 180, 3, 10, 7, true );
00176 addeingabe ( 7, &restp2, black, dblue );
00177
00178 buildgraphics();
00179
00180 }
00181
00182 void tputresourcesdlg :: buttonpressed ( int id )
00183 {
00184 tdialogbox :: buttonpressed ( id );
00185
00186 switch ( id ) {
00187 case 1:
00188 status = 11;
00189 break;
00190 case 2:
00191 status = 10;
00192 break;
00193 case 6:
00194 restp2 = 0;
00195 enablebutton ( 7 );
00196 break;
00197 case 7:
00198 resourcetype = 0;
00199 enablebutton ( 6 );
00200 break;
00201 }
00202
00203 }
00204
00205 void tputresourcesdlg :: run ( void )
00206 {
00207 mousevisible ( true );
00208 do {
00209 tdialogbox :: run ( );
00210 } while ( status < 10 );
00211 if ( status == 11 ) {
00212 tputresources pr ( actmap );
00213 pr.init ( actmap->getCursor().x, actmap->getCursor().y, dist, resourcetype ? 1 : 2, maxresource, minresource );
00214 }
00215 }
00216
00217
00218
00219
00220
00221
00222 void lines(int x1,int y1,int x2,int y2)
00223 {
00224 line(x1,y1,x2,y1,white);
00225 line(x2,y1,x2,y2,darkgray);
00226 line(x1,y2,x2,y2,darkgray);
00227 line(x1,y1,x1,y2,white);
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
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
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 class tplayerchange : public tdialogbox {
00308 public :
00309 int action;
00310 int sel1,sel2;
00311 int bkgcolor;
00312 void init(void);
00313 virtual void run(void);
00314 virtual void buttonpressed(int id);
00315 void anzeige(void);
00316 };
00317
00318
00319
00320
00321 void tplayerchange::init(void)
00322 {
00323 char *s1;
00324
00325 tdialogbox::init();
00326 title = "Player Change";
00327 x1 = 50;
00328 xsize = 370;
00329 y1 = 50;
00330 ysize = 410;
00331 action = 0;
00332 sel1 = 255;
00333 sel2 = 255;
00334 bkgcolor = lightgray;
00335
00336 windowstyle = windowstyle ^ dlg_in3d;
00337
00338 for ( int i=0; i<=8 ; i++ ) {
00339 s1 = new(char[12]);
00340 if (i == 8) {
00341 strcpy(s1,"~N~eutral");
00342 } else {
00343 strcpy(s1,"Player ~");
00344 strcat(s1,strrr(i+1));
00345 strcat(s1,"~");
00346 }
00347 addbutton(s1,20,55+i*30,150,75+i*30,0,1,6+i,true);
00348 addkey(1,ct_1+i);
00349 }
00350
00351
00352 addbutton("X~c~hange",20,ysize - 70,170,ysize - 50,0,1,4,true);
00353 addbutton("~M~erge",200,ysize - 70,350,ysize - 50,0,1,5,true);
00354
00355 addbutton("~D~one",20,ysize - 40,170,ysize - 20,0,1,1,true);
00356 addkey(1,ct_enter);
00357 addbutton("E~x~it",200,ysize - 40,350,ysize - 20,0,1,2,true);
00358
00359 buildgraphics();
00360
00361 for ( int i=0; i<=8 ; i++ ) bar(x1 + 170,y1 + 60 + i*30 ,x1 + 190 ,y1 + 70 + i * 30,20 + ( i << 3 ));
00362
00363 anzeige();
00364
00365 mousevisible(true);
00366 }
00367
00368 void tplayerchange::anzeige(void)
00369 {
00370 int e,b,m[9];
00371 for ( int i=0; i<=8 ; i++ )
00372 m[i] =0;
00373
00374 for ( int i =0; i < actmap->xsize * actmap->ysize ; i++ ) {
00375 int color = actmap->field[i].mineowner();
00376 if ( color >= 0 && color < 8 )
00377 m[color]++;
00378 }
00379 activefontsettings.length = 40;
00380 activefontsettings.background = lightgray;
00381 activefontsettings.color = red;
00382 activefontsettings.justify = lefttext;
00383 activefontsettings.font = schriften.smallarial;
00384 mousevisible(false);
00385 showtext2("Units",x1+210,y1+35);
00386 showtext2("Build.",x1+260,y1+35);
00387 showtext2("Mines",x1+310,y1+35);
00388 for ( int i=0; i<=8 ; i++ ) {
00389 if (i == sel1 ) rectangle (x1 + 16,y1+51+i*30,x1+154,y1+79+i*30, 20 );
00390 else if ( i == sel2 ) rectangle (x1 + 16,y1+51+i*30,x1+154,y1+79+i*30, 28 );
00391 else rectangle (x1 + 16,y1+51+i*30,x1+154,y1+79+i*30, bkgcolor );
00392 e = actmap->player[i].vehicleList.size();
00393 b = actmap->player[i].buildingList.size();
00394 activefontsettings.justify = righttext;
00395 showtext2(strrr(e),x1+200,y1+56+i*30);
00396 showtext2(strrr(b),x1+255,y1+56+i*30);
00397 showtext2(strrr(m[i]),x1+310,y1+56+i*30);
00398 }
00399 mousevisible(true);
00400 }
00401
00402
00403 void tplayerchange::run(void)
00404 {
00405
00406 do {
00407 tdialogbox::run();
00408 if (taste == ct_f1) help ( 1050 );
00409 } while (!((taste == ct_esc) || ((action == 1) || (action ==2))));
00410
00411 }
00412
00413
00414 void tplayerchange::buttonpressed(int id)
00415 {
00416 tdialogbox::buttonpressed(id);
00417 switch (id) {
00418
00419 case 1:
00420 case 2:
00421 action = id;
00422 break;
00423
00424
00425
00426
00427
00428
00429
00430
00431 case 4: {
00432 if ( ( sel1 != 255) && ( sel2 != sel1 ) && ( sel2 != 255 ) && ( sel1 != 8) && ( sel2 != 8 ) ) {
00433 actmap->player[sel1].swap ( actmap->player[sel2] );
00434 anzeige();
00435 }
00436 }
00437 break;
00438 case 5: {
00439 if ( ( sel1 != 255) && ( sel2 != sel1 ) && ( sel2 != 255 ) ) {
00440
00441
00442
00443 if ( sel1 != 8 )
00444 for ( Player::VehicleList::iterator i = actmap->player[sel2].vehicleList.begin(); i != actmap->player[sel2].vehicleList.end(); ) {
00445 (*i)->color = sel1*8;
00446 actmap->player[sel1].vehicleList.push_back ( *i );
00447 i = actmap->player[sel2].vehicleList.erase( i );
00448 }
00449
00450 Player::BuildingList bl = actmap->player[sel2].buildingList;
00451 for ( Player::BuildingList::iterator i = bl.begin(); i != bl.end(); ++i)
00452 (*i)->convert( sel1 );
00453
00454 for (int i =0; i < actmap->xsize * actmap->ysize ; i++ ) {
00455 MapField* fld = &actmap->field[i];
00456 for ( MapField::MineContainer::iterator i = fld->mines.begin(); i != fld->mines.end(); i++ )
00457 if ( i->player == sel2 && sel1 != 8)
00458 i->player = sel1;
00459
00460 }
00461 anzeige();
00462 }
00463 }
00464 break;
00465 case 6:
00466 case 7:
00467 case 8:
00468 case 9:
00469 case 10:
00470 case 11:
00471 case 12:
00472 case 13:
00473 case 14:
00474 if ( id-6 != sel1 ) {
00475 sel2 = sel1;
00476 sel1 = id-6;
00477 anzeige();
00478 }
00479 break;
00480 }
00481 }
00482
00483
00484 void playerchange(void)
00485 {
00486 tplayerchange sc;
00487
00488 sc.init();
00489 sc.run();
00490 sc.done();
00491 mapChanged(actmap);
00492 }
00493
00494
00495
00496
00497 void exchg(int * a1,
00498 int * a2)
00499 {
00500 int ex;
00501
00502 ex = *a1;
00503 *a1 = *a2;
00504 *a2 = ex;
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 #ifndef pbpeditor
00605
00606 void k_savemap(char saveas)
00607 {
00608 ASCString filename;
00609
00610 int nameavail = 0;
00611 if ( !actmap->preferredFileNames.mapname[0].empty() ) {
00612 nameavail = 1;
00613 filename = actmap->preferredFileNames.mapname[0];;
00614 }
00615
00616 if ( saveas || !nameavail ) {
00617 filename = selectFile(mapextension, false);
00618 }
00619 if ( !filename.empty() ) {
00620 mapsaved = true;
00621 actmap->preferredFileNames.mapname[0] = filename;
00622 savemap( filename, actmap );
00623 displaymap();
00624 }
00625 }
00626
00627
00628 void k_loadmap(void)
00629 {
00630 ASCString s1 = selectFile( mapextension, true );
00631 if ( !s1.empty() ) {
00632 StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "loading map " + s1 );
00633 GameMap* mp = mapLoadingExceptionChecker( s1, MapLoadingFunction( tmaploaders::loadmap ));
00634 if ( !mp )
00635 return;
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648 delete actmap;
00649 actmap = mp;
00650
00651 displaymap();
00652 mapsaved = true;
00653 }
00654 }
00655
00656 #else
00657
00658 #include "pbpeditor.cpp"
00659
00660 #endif
00661
00662
00663 void selectUnitFromMap ( GameMap* gamemap, MapCoordinate& pos )
00664 {
00665 SelectFromMap::CoordinateList list;
00666 list.push_back( pos );
00667
00668 SelectFromMap sfm( list, gamemap );
00669 sfm.Show();
00670 sfm.RunModal();
00671
00672 if ( list.empty() )
00673 pos = MapCoordinate( -1, -1 );
00674 else
00675 pos = *list.begin();
00676 }
00677
00678
00679
00680 void setstartvariables(void)
00681 {
00682 activefontsettings.font = schriften.smallarial;
00683 activefontsettings.color = 1;
00684 activefontsettings. background = 0;
00685
00686 mapsaved = true;
00687
00688 }
00689
00690 #if 0
00691
00692 int selectfield(int * cx ,int * cy)
00693 {
00694
00695
00696 actmap->getCursor() = MapCoordinate( *cx, *cy );
00697 displaymap();
00698 tkey ch = ct_invvalue;
00699 do {
00700 if (keypress()) {
00701 ch = r_key();
00702
00703 } else
00704 releasetimeslice();
00705 } while ( ch!=ct_enter && ch!=ct_space && ch!=ct_esc);
00706 *cx=actmap->getCursor().x;
00707 *cy=actmap->getCursor().y;
00708 if ( ch == ct_enter )
00709 return 1;
00710 else if ( ch == ct_esc )
00711 return 0;
00712 else
00713 return 2;
00714 }
00715
00716
00717
00718 Vehicle* selectUnitFromMap()
00719 {
00720 displaymap();
00721 tkey ch = ct_invvalue;
00722 Vehicle* veh = NULL;
00723 do {
00724 if (keypress()) {
00725 ch = r_key();
00726
00727 if ( ch == 'c' && getactfield()->getContainer() )
00728 veh = selectUnitFromContainer( getactfield()->getContainer() );
00729
00730 if ( ch ==ct_enter || ch==ct_space ) {
00731 if ( getactfield()->vehicle )
00732 veh = getactfield()->vehicle;
00733 }
00734 } else
00735 releasetimeslice();
00736
00737
00738 } while ( !veh && ch!=ct_esc);
00739
00740 if ( ch == ct_enter || ct_space )
00741 return veh;
00742 else
00743 return NULL;
00744 }
00745
00746 #endif
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 class ShowPolygonUsingTemps : public PolygonPainterSquareCoordinate {
00824 protected:
00825 virtual void setpointabs ( int x, int y ) {
00826 MapField* ffield = getfield ( x , y );
00827 if (ffield)
00828 ffield->a.temp2 = 1;
00829 };
00830 public:
00831 bool paintPolygon ( const Poly_gon& poly ) {
00832 bool res = PolygonPainterSquareCoordinate::paintPolygon ( poly );
00833 for ( int i = 0; i < poly.vertex.size(); ++i ) {
00834 MapField* ffield = actmap->getField ( poly.vertex[i] );
00835 if (ffield)
00836 ffield->a.temp = 1;
00837 }
00838 return res;
00839 };
00840 };
00841
00842
00843 class PolygonEditor : public SelectFromMap {
00844 protected:
00845 void showFieldMarking( const CoordinateList& coordinateList )
00846 {
00847 Poly_gon poly;
00848 for ( CoordinateList::const_iterator i = coordinateList.begin(); i != coordinateList.end(); ++i )
00849 poly.vertex.push_back( MapCoordinate(*i) );
00850
00851 ShowPolygonUsingTemps sput;
00852 if ( !sput.paintPolygon ( poly ) )
00853 displaymessage("Invalid Polygon !",1 );
00854
00855 repaintMap();
00856 }
00857
00858 public:
00859 PolygonEditor( CoordinateList& list, GameMap* map ) : SelectFromMap( list, map ) {};
00860 };
00861
00862
00863
00864 void editpolygon(Poly_gon& poly)
00865 {
00866 savemap ( "_backup_polygoneditor.map", actmap );
00867
00868 PolygonEditor::CoordinateList list;
00869
00870 for ( Poly_gon::VertexIterator i = poly.vertex.begin(); i != poly.vertex.end(); ++i )
00871 list.push_back( *i );
00872
00873 PolygonEditor cp ( list, actmap );
00874 cp.Show();
00875 cp.RunModal();
00876
00877 poly.vertex.clear();
00878 for ( PolygonEditor::CoordinateList::iterator i = list.begin(); i != list.end(); ++i )
00879 poly.vertex.push_back( *i );
00880 }
00881
00882
00883
00884 void newmap(void)
00885 {
00886 GameMap* map = createNewMap();
00887 if ( map ) {
00888 delete actmap;
00889 actmap = map;
00890
00891 mapChanged( actmap );
00892
00893 }
00894 }
00895
00896
00897
00898
00899
00900
00901 class BuildingValues : public tdialogbox {
00902 int action;
00903 Building& gbde;
00904 int rs,mrs;
00905 Resources plus,mplus, biplus,storage;
00906 int col;
00907 int damage;
00908 char tvisible;
00909 char name[260];
00910 int ammo[waffenanzahl];
00911 virtual void buttonpressed(int id);
00912 int lockmaxproduction;
00913 TemporaryContainerStorage buildingBackup;
00914
00915 public :
00916 BuildingValues ( Building& building ) : gbde ( building ), buildingBackup ( &building ) {};
00917 void init(void);
00918 virtual void run(void);
00919 };
00920
00921
00922 void BuildingValues::init(void)
00923 {
00924 char b;
00925
00926 for ( int i = 0; i< waffenanzahl; i++ )
00927 ammo[i] = gbde.ammo[i];
00928
00929 lockmaxproduction = 1;
00930
00931 tdialogbox::init();
00932 action = 0;
00933 title = "Building Values";
00934 x1 = 0;
00935 xsize = 640;
00936 y1 = 10;
00937 ysize = 480;
00938
00939 action = 0;
00940
00941 windowstyle = windowstyle ^ dlg_in3d;
00942
00943 storage = gbde.actstorage;
00944 plus = gbde.plus;
00945 mplus = gbde.maxplus;
00946 rs = gbde.researchpoints;
00947 mrs = gbde.maxresearchpoints;
00948 tvisible = gbde.visible;
00949 biplus = gbde.bi_resourceplus;
00950 col = gbde.color / 8;
00951 damage = gbde.damage;
00952
00953 strcpy( name, gbde.name.c_str() );
00954
00955 addbutton("~N~ame",15,50,215,70,1,1,10,true);
00956 addeingabe(10,&name[0],0,25);
00957
00958 addbutton("~E~nergy-Storage",15,90,215,110,2,1,1,true);
00959 addeingabe(1,&storage.energy,0,gbde.getStorageCapacity().resource(0));
00960
00961 addbutton("~M~aterial-Storage",15,130,215,150,2,1,2,true);
00962 addeingabe(2,&storage.material,0,gbde.getStorageCapacity().resource(1));
00963
00964 addbutton("~F~uel-Storage",15,170,215,190,2,1,3,true);
00965 addeingabe(3,&storage.fuel,0,gbde.getStorageCapacity().resource(2));
00966
00967 if ( gbde.typ->hasFunction( ContainerBaseType::MatterConverter ) ||
00968 gbde.typ->hasFunction( ContainerBaseType::SolarPowerPlant ) ||
00969 gbde.typ->hasFunction( ContainerBaseType::WindPowerPlant ) ||
00970 gbde.typ->hasFunction( ContainerBaseType::MiningStation ) ||
00971 gbde.typ->hasFunction( ContainerBaseType::ResourceSink ))
00972 b = true;
00973 else
00974 b = false;
00975
00976 addbutton("Energy-Max-Plus",230,50,430,70,2,1,13,b);
00977 addeingabe(13,&mplus.energy,0,gbde.typ->maxplus.energy);
00978
00979 if ( gbde.typ->hasFunction( ContainerBaseType::MatterConverter ) ||
00980 gbde.typ->hasFunction( ContainerBaseType::MiningStation ) ||
00981 gbde.typ->hasFunction( ContainerBaseType::ResourceSink ))
00982 b = true;
00983 else
00984 b = false;
00985
00986
00987 addbutton("Energ~y~-Plus",230,90,430,110,2,1,4,b);
00988 addeingabe(4,&plus.energy,0,mplus.energy);
00989
00990 if ( ((gbde.typ->hasFunction( ContainerBaseType::MatterConverter) || gbde.typ->hasFunction( ContainerBaseType::MiningStation)) && gbde.typ->efficiencymaterial )
00991 || gbde.typ->hasFunction( ContainerBaseType::ResourceSink ) )
00992 b = true;
00993 else
00994 b = false;
00995
00996 addbutton("Material-Max-Plus",230,130,430,150,2,1,14,b);
00997 addeingabe(14,&mplus.material,0,gbde.typ->maxplus.material);
00998
00999 addbutton("M~a~terial-Plus",230,170,430,190,2,1,5,b);
01000 addeingabe(5,&plus.material,0,mplus.material);
01001
01002 if ( ((gbde.typ->hasFunction( ContainerBaseType::MatterConverter) || gbde.typ->hasFunction( ContainerBaseType::MiningStation)) && gbde.typ->efficiencyfuel )
01003 || gbde.typ->hasFunction( ContainerBaseType::ResourceSink ) )
01004 b = true;
01005 else
01006 b = false;
01007
01008 addbutton("Fuel-Max-Plus",230,210,430,230,2,1,15,b);
01009 addeingabe(15,&mplus.fuel,0,gbde.typ->maxplus.fuel);
01010
01011 addbutton("F~u~el-Plus",230,250,430,270,2,1,6,b);
01012 addeingabe(6,&plus.fuel, 0, mplus.fuel);
01013
01014 if ( gbde.typ->hasFunction( ContainerBaseType::Research) || ( gbde.typ->maxresearchpoints > 0))
01015 b = true;
01016 else
01017 b = false;
01018
01019 addbutton("~R~esearch-Points",15,210,215,230,2,1,9,b);
01020 if ( gbde.typ->hasFunction(ContainerBaseType::Research))
01021 addeingabe(9,&rs,0,gbde.typ->maxresearchpoints);
01022 else
01023 addeingabe(9,&rs,gbde.typ->maxresearchpoints,gbde.typ->maxresearchpoints);
01024
01025 addbutton("Ma~x~research-Points",15,250,215,270,2,1,11,b);
01026 if ( gbde.typ->hasFunction(ContainerBaseType::Research))
01027 addeingabe(11,&mrs,0,gbde.typ->maxresearchpoints);
01028 else
01029 addeingabe(11,&mrs,gbde.typ->maxresearchpoints,gbde.typ->maxresearchpoints);
01030
01031
01032 addbutton("~V~isible",15,290,215,300,3,1,12,true);
01033 addeingabe(12,&tvisible,0,lightgray);
01034
01035 addbutton("~L~ock MaxPlus ratio",230,290,430,300,3,1,120,true);
01036 addeingabe(120,&lockmaxproduction,0,lightgray);
01037
01038
01039 addbutton("~C~olor",230,370,430,390,2,1,104,true);
01040 addeingabe(104,&col,0,8);
01041
01042 addbutton("~D~amage",230,410,430,430,2,1,105,true);
01043 addeingabe(105,&damage,0,99);
01044
01045
01046 addbutton("BI energy plus",15,330,215,350,2,1,101,1);
01047 addeingabe(101,&biplus.energy,0,maxint);
01048
01049 addbutton("BI material plus",230,330,430,350,2,1,102,1);
01050 addeingabe(102,&biplus.material,0,maxint);
01051
01052 addbutton("BI fuel plus",15,370,215,390,2,1,103,1);
01053 addeingabe(103,&biplus.fuel,0,maxint);
01054
01055
01056 addbutton("~S~et Values",10,ysize - 40, xsize/3-5,ysize - 10,0,1,7,true);
01057 addkey(7,ct_enter);
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067 addbutton("~C~ancel",xsize/3*2+5,ysize - 40,xsize-10,ysize - 10,0,1,8,true);
01068 addkey(8, ct_esc );
01069
01070
01071 for ( int i = 0; i < waffenanzahl; i++ ) {
01072 addbutton ( cwaffentypen[i], 460, 90+i*40, 620, 110+i*40, 2, 1, 200+i, 1 );
01073 addeingabe(200+i, &ammo[i], 0, maxint );
01074 }
01075
01076 buildgraphics();
01077 line(x1+450, y1+45, x1+450, y1+55+9*40, darkgray );
01078 activefontsettings.length =0;
01079 activefontsettings.font = schriften.smallarial;
01080 showtext2("ammunition:", x1 + 460, y1 + 50 );
01081
01082 mousevisible(true);
01083 }
01084
01085
01086 void BuildingValues::run(void)
01087 {
01088 do {
01089 tdialogbox::run();
01090 } while (!((taste == ct_esc) || (action == 1)));
01091 }
01092
01093
01094 void BuildingValues::buttonpressed(int id)
01095 {
01096 switch (id) {
01097 case 4:
01098 case 5:
01099 case 6: {
01100 int changed_resource = id - 4;
01101 for ( int r = 0; r < 3; r++ )
01102 if ( r != changed_resource )
01103 if ( mplus.resource(changed_resource) ) {
01104 int a = mplus.resource(r) * plus.resource(changed_resource) / mplus.resource(changed_resource);
01105 if ( a != plus.resource(r) ) {
01106 plus.resource(r) = a;
01107 showbutton ( 4 + r );
01108 }
01109 }
01110 }
01111 break;
01112 case 13:
01113 case 14:
01114 case 15: {
01115 int changed_resource = id - 13;
01116 if ( lockmaxproduction )
01117 for ( int r = 0; r < 3; r++ )
01118 if ( r != changed_resource )
01119 if ( gbde.typ->maxplus.resource(changed_resource) ) {
01120 int a = gbde.typ->maxplus.resource(r) * mplus.resource(changed_resource) / gbde.typ->maxplus.resource(changed_resource);
01121 if ( a != mplus.resource(r) ) {
01122 mplus.resource(r) = a;
01123 showbutton ( 13 + r );
01124 }
01125 }
01126
01127 for ( int r = 0; r < 3; r++ ) {
01128 if ( (mplus.resource(r) >= 0 && plus.resource(r) > mplus.resource(r) ) ||
01129 (mplus.resource(r) < 0 && plus.resource(r) < mplus.resource(r) )) {
01130 plus.resource(r) = mplus.resource(r);
01131 showbutton ( 4 + r );
01132 }
01133 addeingabe(4+r, &plus.resource(r), 0, mplus.resource(r) );
01134 }
01135 }
01136 break;
01137 case 7: {
01138 mapsaved = false;
01139 action = 1;
01140 gbde.actstorage = storage;
01141
01142 gbde.plus = plus;
01143 gbde.maxplus = mplus;
01144 if ( col != gbde.color/8 )
01145 gbde.convert ( col );
01146
01147 gbde.researchpoints = rs;
01148 gbde.maxresearchpoints = mrs;
01149 gbde.visible = tvisible;
01150 gbde.bi_resourceplus = biplus;
01151 gbde.name = name;
01152 gbde.damage = damage;
01153 for ( int i = 0; i< waffenanzahl; i++ )
01154 gbde.ammo[i] = ammo[i];
01155
01156 }
01157 break;
01158 case 8:
01159 action = 1;
01160 break;
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190 case 110:
01191 help ( 41 );
01192 break;
01193
01194 }
01195 }
01196
01197
01198 void changebuildingvalues( Building& b )
01199 {
01200 BuildingValues bval ( b );
01201 bval.init();
01202 bval.run();
01203 bval.done();
01204
01205 displaymap();
01206 }
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349 class StringSelector : public tstringselect {
01350 const char** text;
01351 public :
01352 int lastchoice;
01353 StringSelector ( const char* title_, const char** text_, int itemNum_ ) : text ( text_ ) {
01354 lastchoice = 0;
01355 numberoflines = itemNum_;
01356 title = title_;
01357 };
01358 virtual void setup(void);
01359 virtual void buttonpressed(int id);
01360 virtual void run(void);
01361 virtual void get_text(int nr);
01362 };
01363
01364 void StringSelector ::setup(void)
01365 {
01366 action = 0;
01367 ey = ysize - 90;
01368 startpos = lastchoice;
01369 addbutton("~O~k",20,ysize - 50,xsize-20,ysize - 20,0,1,13,true);
01370 addkey ( 13, ct_enter );
01371 }
01372
01373
01374 void StringSelector ::buttonpressed(int id)
01375 {
01376 tstringselect::buttonpressed(id);
01377 switch (id) {
01378
01379 case 12:
01380 if ( redline >= 0 )
01381 action = id-10;
01382 break;
01383
01384 case 13:
01385 action = id-10;
01386 break;
01387 }
01388 }
01389
01390
01391 void StringSelector ::get_text(int nr)
01392 {
01393 strcpy(txt, text[nr] );
01394 }
01395
01396
01397 void StringSelector ::run(void)
01398 {
01399 do {
01400 tstringselect::run();
01401 if ( taste == ct_enter ) {
01402 if ( redline >= 0 )
01403 action = 2;
01404 else
01405 action = 3;
01406 }
01407 } while ( action == 0 );
01408 }
01409
01410
01411 int selectString( int lc, const char* title, const char** text, int itemNum )
01412 {
01413 StringSelector ss ( title, text, itemNum );
01414 ss.lastchoice = lc;
01415 ss.init();
01416 ss.run();
01417 ss.done();
01418 return ss.redline;
01419 }
01420
01421
01422 class EditAiParam : public tdialogbox {
01423 Vehicle* unit;
01424 TemporaryContainerStorage tus;
01425 int action;
01426 AiParameter& aiv;
01427 int z;
01428 public:
01429 EditAiParam ( Vehicle* veh, int player ) : unit ( veh ), tus ( veh ), aiv ( *veh->aiparam[player] ) {};
01430 void init ( );
01431 void run ( );
01432 void buttonpressed ( int id );
01433 int getcapabilities ( void ) {
01434 return 1;
01435 };
01436 };
01437
01438
01439 void EditAiParam::init( )
01440 {
01441 tdialogbox::init();
01442 action = 0;
01443 title = "Unit AI Values";
01444
01445 windowstyle = windowstyle ^ dlg_in3d;
01446
01447 x1 = 20;
01448 xsize = 600;
01449 y1 = 40;
01450 ysize = 400;
01451 int w = (xsize - 60) / 2;
01452 action = 0;
01453
01454 addbutton("dest ~X~",50,80,250,100,2,1,1,true);
01455 addeingabe(1, &aiv.dest.x, minint, maxint);
01456
01457 addbutton("dest ~Y~",50,120,250,140,2,1,2,true);
01458 addeingabe(2, &aiv.dest.y, minint, maxint);
01459
01460 z = aiv.dest.getNumericalHeight();
01461 addbutton("dest ~Z~",50,160,250,180,2,1,3,true);
01462 addeingabe(3, &z, minint, maxint);
01463
01464 addbutton("dest ~N~WID",50,200,250,220,2,1,4,true);
01465 addeingabe(4, &aiv.dest_nwid, minint, maxint);
01466
01467 addbutton("~V~alue",410,80,570,100,2,1,10,true);
01468 addeingabe( 10, &aiv.value, minint, maxint );
01469
01470 addbutton("~A~dded value",410,120,570,140,2,1,11,true);
01471 addeingabe( 11, &aiv.addedValue, minint, maxint );
01472
01473 addbutton("~R~eset task after completion",410,160,570,180,3,1,12,true);
01474 addeingabe( 12, &aiv.resetAfterJobCompletion, black, dblue );
01475
01476
01477 addbutton("~S~elect Dest",50,240,250,260,0,1,22,true);
01478
01479 addbutton("~T~ask",20,ysize - 70,20 + w,ysize - 50,0,1,20,true);
01480 addbutton("~J~ob",40 + w,ysize - 70,40 + 2 * w,ysize - 50,0,1,21,true);
01481
01482 addbutton("~S~et Values",20,ysize - 40,20 + w,ysize - 10,0,1,30,true);
01483 addkey(30,ct_enter );
01484 addbutton("~C~ancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,31,true);
01485 addkey(31,ct_esc );
01486
01487 buildgraphics();
01488 mousevisible(true);
01489 }
01490
01491
01492 void EditAiParam::run(void)
01493 {
01494 do {
01495 tdialogbox::run();
01496 } while ( !action );
01497 }
01498
01499
01500 void EditAiParam::buttonpressed(int id)
01501 {
01502 switch (id) {
01503 case 20 :
01504 aiv.setTask( AiParameter::Task( selectString ( aiv.getTask(), "Select Task", AItasks , AiParameter::taskNum) ));
01505 break;
01506 case 21 : {
01507 AiParameter::JobList j;
01508 j.push_back ( AiParameter::Job( selectString ( aiv.getJob(), "Select Job", AIjobs , AiParameter::jobNum) ) );
01509 aiv.setJob ( j );
01510 }
01511 break;
01512
01513
01514
01515
01516
01517
01518
01519 case 30 :
01520 action = 1;
01521 aiv.dest.setnum ( aiv.dest.x, aiv.dest.y, z );
01522 break;
01523 case 31 :
01524 action = 1;
01525 tus.restore();
01526 break;
01527 }
01528 }
01529
01530
01531
01532
01533 class UnitPropertyEditor: public tdialogbox {
01534 TemporaryContainerStorage tus;
01535 int dirx,diry;
01536 int action;
01537 Vehicle* unit;
01538 int w2, heightxs;
01539 char namebuffer[1000];
01540 char reactionfire;
01541 int owner;
01542 public:
01543
01544 UnitPropertyEditor ( Vehicle* v ) : tus ( v ), unit ( v ) {};
01545 void init( void );
01546 void run( void );
01547 void buttonpressed( int id );
01548 };
01549
01550
01551 void UnitPropertyEditor::init( )
01552 {
01553 int w;
01554 char *weaponammo;
01555
01556 tdialogbox::init();
01557 action = 0;
01558 title = "Unit-Values";
01559
01560 windowstyle = windowstyle ^ dlg_in3d;
01561
01562 x1 = 20;
01563 xsize = 600;
01564 y1 = 0;
01565 ysize = 600;
01566 w = (xsize - 60) / 2;
01567 w2 = (xsize - 40) / 8;
01568 dirx= x1 + 300;
01569 diry= y1 + 100;
01570 action = 0;
01571
01572 owner = unit->getOwner();
01573
01574
01575 strcpy ( namebuffer, unit->name.c_str() );
01576
01577 addbutton("~N~ame",50,80,250,100,1,1,29,true);
01578 addeingabe(29, namebuffer, 0, 100);
01579
01580 addbutton("E~x~p of Unit",50,120,250,140,2,1,1,true);
01581 addeingabe(1, &unit->experience, 0, maxunitexperience);
01582
01583 addbutton("~D~amage of Unit",50,160,250,180,2,1,2,true);
01584 addeingabe(2, &unit->damage, 0, 100 );
01585
01586 addbutton("~F~uel of Unit",50,200,250,220,2,1,3,true);
01587 addeingabe( 3, &unit->tank.fuel, 0, unit->getStorageCapacity().fuel );
01588
01589 addbutton("~M~aterial",50,240,250,260,2,1,12,true);
01590 addeingabe(12,&unit->tank.material, 0, unit->getStorageCapacity().material );
01591
01592 addbutton("AI Parameter", 50, 280, 250, 300, 0, 1, 115, true );
01593
01594 addbutton("Unit owner",50,320,250,340,2,1,116,true);
01595 addeingabe(116, &owner, 0, 7 );
01596
01597 int unitheights = 0;
01598 heightxs = 520;
01599 MapField* fld = getfield ( unit->xpos, unit->ypos);
01600 if ( fld && fld->vehicle == unit ) {
01601 npush ( unit->height );
01602 for ( int i=0; i<=7 ; i++) {
01603 unit->height = 1 << i;
01604 if (( ( unit->height & unit->typ->height ) > 0) && ( terrainaccessible( fld, unit ) == 2)) {
01605 addbutton("",20+( i * w2),heightxs,w2 * (i +1 ),heightxs+24,0,1,i+4,true);
01606 addkey(i+4,ct_0+i);
01607 }
01608 unitheights |= 1 << i;
01609 }
01610 npop ( unit->height );
01611 }
01612
01613 if ( unit->typ->hasFunction( ContainerBaseType::NoReactionfire ))
01614 unit->reactionfire.disable();
01615
01616 addbutton("~R~eactionfire",dirx-50,250,dirx+50,260,3,1,22,(unit->typ->hasFunction( ContainerBaseType::NoReactionfire )) == 0 );
01617 reactionfire = unit->reactionfire.getStatus();
01618 addeingabe(22, &reactionfire, 0, lightgray);
01619
01620 addbutton("~S~et Values",20,ysize - 40,20 + w,ysize - 10,0,1,30,true);
01621 addkey(30,ct_enter );
01622 addbutton("~C~ancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,31,true);
01623 addkey(31,ct_esc );
01624
01625 const int maxeditable = 10;
01626
01627 for ( int i =0; i < unit->typ->weapons.count; i++) {
01628 if (i < maxeditable) {
01629 weaponammo = new(char[25]);
01630 strcpy(weaponammo,"Wpn Ammo ");
01631 strcat(weaponammo,strrr(i+1));
01632 addbutton(weaponammo,410,80+i*40,570,100+i*40,2,1,33+i,true);
01633 addeingabe( 33+i, &unit->ammo[i], 0, unit->typ->weapons.weapon[i].count );
01634 } else
01635 showtext2("6 weapons max at the moment",x1+410,y1+80+maxeditable*40);
01636
01637 }
01638
01639 buildgraphics();
01640
01641 mousevisible(false);
01642
01643
01644 static bool heightIconsLoaded = false;
01645 static void* iconsheight[8];
01646 static void* iconspfeil[8];
01647
01648
01649 if ( !heightIconsLoaded ) {
01650 {
01651 tnfilestream stream ("height.raw",tnstream::reading);
01652 int w;
01653 for ( int i = 0; i <= 7; i++)
01654 stream.readrlepict( &iconsheight[i],false,&w);
01655 }
01656 {
01657 tnfilestream stream ("pfeil-a0.raw", tnstream::reading);
01658 for ( int i=0; i<8 ; i++ )
01659 stream.readrlepict( &iconspfeil[i], false, &w);
01660 }
01661 }
01662
01663
01664
01665 if ( unitheights )
01666 for ( int i=0; i<=7 ; i++) {
01667 if ( unit->height == (1 << i) )
01668 bar(x1 + 25+( i * w2),y1 + heightxs-5,x1 + w2 * (i +1 ) - 5,y1 + heightxs-3,red);
01669
01670 if ( unitheights & ( 1 << i ))
01671 putimage(x1 + 28+( i * w2), y1 + heightxs + 2 ,iconsheight[i]);
01672 }
01673
01674
01675 float radius = 50;
01676 float pi = 3.14159265;
01677 for ( int i = 0; i < sidenum; i++ ) {
01678
01679 int x = (int) (dirx + radius * sin ( 2 * pi * (float) i / (float) sidenum ));
01680 int y = (int) (diry - radius * cos ( 2 * pi * (float) i / (float) sidenum ));
01681
01682 addbutton("", x-10, y - 10, x + 10, y + 10,0,1,14+i,true);
01683 enablebutton ( 14 + i );
01684 void* pic = rotatepict ( iconspfeil[0], directionangle[i] );
01685 int h,w;
01686 getpicsize ( pic, w, h );
01687 putspriteimage ( x1 + x - w/2, y1 + y - h/2, pic );
01688 free( pic );
01689 }
01690
01691
01692 mousevisible(true);
01693 }
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709 void UnitPropertyEditor::run(void)
01710 {
01711 do {
01712 tdialogbox::run();
01713 } while ( !action );
01714 }
01715
01716
01717 void UnitPropertyEditor::buttonpressed(int id)
01718 {
01719 int ht;
01720
01721 switch (id) {
01722 case 3:
01723
01724
01725
01726
01727 break;
01728
01729 case 4 :
01730 case 5 :
01731 case 6 :
01732 case 7 :
01733 case 8 :
01734 case 9 :
01735 case 10 :
01736 case 11 :
01737 {
01738 int h = 1 << ( id - 4 );
01739 bar(x1 +20,y1 + heightxs-5,x1 + 480,y1 + heightxs-3,lightgray);
01740 for (int i=0; i<=7 ; i++) {
01741 ht = 1 << i;
01742 if ( ht == h ) bar(x1 + 25+( i * w2),y1 + heightxs-5,x1 + w2 * (i +1 ) - 5,y1 + heightxs-3,red);
01743 }
01744 unit->height = h;
01745 unit->setMovement ( unit->typ->movement[ getFirstBit ( unit->height ) ], 0 );
01746 }
01747 break;
01748 case 12:
01749
01750
01751
01752
01753 break;
01754
01755 case 14 :
01756 case 15 :
01757 case 16 :
01758 case 17 :
01759 case 18 :
01760 case 19 :
01761 case 20 :
01762 case 21 : {
01763 unit->direction = id-14;
01764 bar(dirx + x1 -fieldsizex/2, diry + y1 - fieldsizey/2 ,dirx + x1 + fieldsizex/2 ,diry + y1 +fieldsizey/2,lightgray);
01765
01766 }
01767 break;
01768 case 30 : {
01769 mapsaved = false;
01770 action = 1;
01771 if ( reactionfire ) {
01772 unit->reactionfire.status = Vehicle::ReactionFire::ready;
01773 } else
01774 unit->reactionfire.status = Vehicle::ReactionFire::off;
01775
01776 unit->name = namebuffer;
01777 if ( owner != unit->getOwner() )
01778 unit->convert( owner );
01779 }
01780 break;
01781 case 31 :
01782 action = 1;
01783 tus.restore();
01784 break;
01785 case 115: {
01786 static int player = 0;
01787 player = getid("player",player,0,7);
01788 if ( !unit->aiparam[player] )
01789 unit->aiparam[player] = new AiParameter ( unit );
01790
01791 EditAiParam eap ( unit, player );
01792 eap.init();
01793 eap.run();
01794 }
01795 }
01796 }
01797
01798
01799 void changeunitvalues(Vehicle* ae)
01800 {
01801 if ( !ae )
01802 return;
01803
01804 UnitPropertyEditor units ( ae );
01805 units.init();
01806 units.run();
01807 units.done();
01808 }
01809
01810
01811
01812
01813 class tres: public tdialogbox {
01814 MapField* pf2;
01815 public :
01816 int action;
01817 int fuel,material;
01818 void init(void);
01819 virtual void run(void);
01820 virtual void buttonpressed(int id);
01821 };
01822
01823
01824
01825 void tres::init(void)
01826 {
01827 int w;
01828
01829 tdialogbox::init();
01830 action = 0;
01831 title = "Resources";
01832 x1 = 170;
01833 xsize = 200;
01834 y1 = 70;
01835 ysize = 200;
01836 w = (xsize - 60) / 2;
01837 action = 0;
01838 pf2 = getactfield();
01839 fuel = pf2->fuel;
01840 material = pf2->material;
01841
01842 windowstyle = windowstyle ^ dlg_in3d;
01843
01844 activefontsettings.length = 200;
01845
01846 addbutton("~F~uel (0-255)",50,70,150,90,2,1,1,true);
01847 addeingabe(1,&fuel,0,255);
01848 addbutton("~M~aterial (0-255)",50,110,150,130,2,1,2,true);
01849 addeingabe(2,&material,0,255);
01850
01851 addbutton("~S~et Vals",20,ysize - 40,20 + w,ysize - 10,0,1,7,true);
01852 addkey(7,ct_enter);
01853 addbutton("~C~ancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,8,true);
01854
01855 buildgraphics();
01856
01857 mousevisible(true);
01858 }
01859
01860
01861 void tres::run(void)
01862 {
01863 do {
01864 tdialogbox::run();
01865 } while (!((taste == ct_esc) || (action == 1)));
01866 }
01867
01868
01869 void tres::buttonpressed(int id)
01870 {
01871 if (id == 7) {
01872 mapsaved = false;
01873 action = 1;
01874 pf2->fuel = fuel;
01875 pf2->material = material;
01876 }
01877 if (id == 8) action = 1;
01878 }
01879
01880
01881 void changeresource(void)
01882 {
01883 tres resource;
01884
01885 resource.init();
01886 resource.run();
01887 resource.done();
01888 }
01889
01890
01891
01892 class tminestrength: public tdialogbox {
01893 MapField* pf2;
01894 public :
01895 int action;
01896 int strength;
01897 void init(void);
01898 virtual void run(void);
01899 virtual void buttonpressed(int id);
01900 };
01901
01902
01903
01904 void tminestrength::init(void)
01905 {
01906 int w;
01907
01908 tdialogbox::init();
01909 action = 0;
01910 title = "Minestrength";
01911 x1 = 170;
01912 xsize = 200;
01913 y1 = 70;
01914 ysize = 160;
01915 w = (xsize - 60) / 2;
01916 action = 0;
01917 pf2 = getactfield();
01918 strength = pf2->mines.begin()->strength;
01919
01920 windowstyle = windowstyle ^ dlg_in3d;
01921
01922 activefontsettings.length = 200;
01923
01924 addbutton("~S~trength (0-255)",30,70,170,90,2,1,1,true);
01925 addeingabe(1,&strength,0,255);
01926
01927 addbutton("~S~et Vals",20,ysize - 40,20 + w,ysize - 10,0,1,7,true);
01928 addkey(7,ct_enter);
01929 addbutton("~C~ancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,8,true);
01930
01931 buildgraphics();
01932
01933 mousevisible(true);
01934 }
01935
01936
01937 void tminestrength::run(void)
01938 {
01939 do {
01940 tdialogbox::run();
01941 } while (!((taste == ct_esc) || (action == 1)));
01942 }
01943
01944
01945 void tminestrength::buttonpressed(int id)
01946 {
01947 if (id == 7) {
01948 mapsaved = false;
01949 action = 1;
01950 pf2->mines.begin()->strength = strength;
01951 }
01952 if (id == 8) action = 1;
01953 }
01954
01955
01956 void changeminestrength(void)
01957 {
01958 if ( getactfield()->mines.empty() )
01959 return;
01960
01961 tminestrength ms;
01962 ms.init();
01963 ms.run();
01964 ms.done();
01965 }
01966
01967
01968 #if 0
01969
01970
01971 class tladeraum : public tdialogbox {
01972 protected:
01973 int maxusable;
01974 int itemsperline;
01975 int action;
01976 virtual const char* getinfotext ( int pos );
01977 void displayinfotext ( void );
01978
01979 virtual void additem ( void ) = 0;
01980 virtual void removeitem ( int pos ) = 0;
01981 virtual void checkforadditionalkeys ( tkey ch );
01982 void displayallitems ( void );
01983 int mouseoverfield ( int pos );
01984 virtual void displaysingleitem ( int pos, int x, int y ) = 0;
01985 void displaysingleitem ( int pos );
01986 int cursorpos;
01987 virtual void finish ( int cancel ) = 0;
01988 int getcapabilities ( void ) {
01989 return 1;
01990 };
01991 virtual void redraw ( void );
01992 public :
01993 void init( char* ttl );
01994 virtual void run(void);
01995 virtual void buttonpressed(int id);
01996 void done(void);
01997 };
01998
01999 void tladeraum::redraw ( void )
02000 {
02001 tdialogbox::redraw();
02002 displayallitems();
02003 }
02004
02005
02006 void tladeraum::init( char* ttl )
02007 {
02008 maxusable = 18;
02009
02010 itemsperline = 8;
02011
02012 npush ( farbwahl );
02013 cursorpos = 0;
02014
02015 tdialogbox::init();
02016 title = ttl;
02017 x1 = 20;
02018 xsize = 600;
02019 y1 = 50;
02020 ysize = 400;
02021 int w = (xsize - 60) / 2;
02022 action = 0;
02023
02024 windowstyle = windowstyle ^ dlg_in3d;
02025
02026 addbutton("~N~ew",20,40,100,70,0,1,1,true);
02027 addbutton("~E~rase",120,40,220,70,0,1,2,true);
02028
02029 addbutton("~O~K",20,ysize - 40,20 + w,ysize - 10,0,1,7,true);
02030 addkey(7,ct_enter);
02031 addbutton("Cancel",40 + w,ysize - 40,40 + 2 * w,ysize - 10,0,1,8,true);
02032 addkey(8,ct_esc );
02033
02034 buildgraphics();
02035
02036 displayallitems();
02037 displayinfotext();
02038
02039 }
02040
02041 void tladeraum :: displayallitems ( void )
02042 {
02043 for ( int i = 0; i < 32; i++ )
02044 displaysingleitem ( i );
02045 }
02046
02047
02048 void tladeraum :: displaysingleitem ( int pos )
02049 {
02050 int x = x1 + 28 + (pos % itemsperline) * fielddistx;
02051 int y = y1 + 88 + (pos / itemsperline) * fielddisty * 3;
02052 putspriteimage( x, y, icons.stellplatz );
02053 if ( pos >= maxusable )
02054 putspriteimage( x, y, icons.X );
02055
02056 displaysingleitem ( pos, x, y );
02057 }
02058
02059 int tladeraum :: mouseoverfield ( int pos )
02060 {
02061 int x = x1 + 28 + (pos % itemsperline) * fielddistx;
02062 int y = y1 + 88 + (pos / itemsperline) * fielddisty * 3;
02063 return mouseinrect ( x, y, x+fieldsizex, y + fieldsizey );
02064 }
02065
02066 const char* tladeraum :: getinfotext( int pos )
02067 {
02068 return NULL;
02069 }
02070
02071 void tladeraum :: checkforadditionalkeys ( tkey ch )
02072 {
02073 }
02074
02075 void tladeraum::displayinfotext ( void )
02076 {
02077 npush ( activefontsettings );
02078 activefontsettings.background = lightgray;
02079 activefontsettings.color = red;
02080 activefontsettings.length = 185;
02081 activefontsettings.font = schriften.smallarial;
02082 const char* it = getinfotext( cursorpos );
02083 if ( it )
02084 showtext2(it, x1 + 240, y1 + 50);
02085 npop ( activefontsettings );
02086 }
02087
02088 void tladeraum::run(void)
02089 {
02090 mousevisible( true );
02091 do {
02092 tdialogbox::run();
02093
02094 checkforadditionalkeys ( taste );
02095 int oldpos = cursorpos;
02096 switch (taste) {
02097 case ct_up:
02098 case ct_8k:
02099 cursorpos -= itemsperline;
02100 break;
02101 case ct_left:
02102 case ct_4k:
02103 cursorpos--;
02104 break;
02105 case ct_right:
02106 case ct_6k:
02107 cursorpos++;
02108 break;
02109 case ct_down:
02110 case ct_2k:
02111 cursorpos += itemsperline;
02112 break;
02113 }
02114 if ( cursorpos < 0 )
02115 cursorpos = 0;
02116 if ( cursorpos >= 32 )
02117 cursorpos = 31;
02118
02119 if ( mouseparams.taste == 1)
02120 for ( int i = 0; i < 32; i++ )
02121 if ( mouseoverfield ( i ))
02122 cursorpos = i;
02123
02124 if ( cursorpos != oldpos ) {
02125 displaysingleitem ( oldpos );
02126 displaysingleitem ( cursorpos );
02127 displayinfotext();
02128 }
02129
02130 } while ( !action );
02131 finish ( action == 1 );
02132
02133 }
02134
02135
02136 void tladeraum::buttonpressed( int id )
02137 {
02138 if (id == 1) {
02139 additem ();
02140 redraw();
02141 }
02142 if (id == 2) {
02143 removeitem ( cursorpos );
02144 displayallitems();
02145 }
02146 if (id == 7) {
02147 mapsaved = false;
02148 action = 2;
02149 }
02150 if (id == 8)
02151 action = 1;
02152
02153 }
02154
02155
02156 void tladeraum::done(void)
02157 {
02158 tdialogbox::done();
02159 npop ( farbwahl );
02160 ch = 0;
02161 }
02162 #endif
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246 #if 0
02247
02248
02249
02250 class tvehiclecargo : public tladeraum {
02251 TemporaryContainerStorage tus;
02252 protected:
02253 Vehicle* transport;
02254 virtual const char* getinfotext ( int pos );
02255 virtual void additem ( void );
02256 virtual void removeitem ( int pos );
02257 virtual void checkforadditionalkeys ( tkey ch );
02258 void displaysingleitem ( int pos, int x, int y );
02259 virtual void finish ( int cancel );
02260
02261 public:
02262 tvehiclecargo ( Vehicle* unit ) : tus ( unit, true ), transport ( unit ) {};
02263 void init ( );
02264
02265
02266 };
02267
02268
02269 const char* tvehiclecargo :: getinfotext ( int pos )
02270 {
02271 if ( transport->cargo.size() <= pos )
02272 return NULL;
02273
02274 Vehicle* veh = transport->cargo[pos];
02275 if ( !veh )
02276 return NULL;
02277
02278 if ( !veh->name.empty() )
02279 return veh->name.c_str();
02280 else if ( !veh->typ->name.empty() )
02281 return veh->typ->name.c_str();
02282 else
02283 return veh->typ->description.c_str();
02284 }
02285
02286
02287 void tvehiclecargo :: init ( )
02288 {
02289 tladeraum::init ( "cargo" );
02290 }
02291
02292 void tvehiclecargo :: displaysingleitem ( int pos, int x, int y )
02293 {
02294 if ( transport->cargo.size() > pos && transport->cargo[pos] )
02295 transport->cargo[ pos ]->typ->paint( getActiveSurface(), SPoint ( x, y), farbwahl );
02296 }
02297
02298 void tvehiclecargo :: additem ( void )
02299 {
02300
02301 }
02302
02303 void tvehiclecargo :: removeitem ( int pos )
02304 {
02305 if ( transport->cargo.size() > pos && transport->cargo[pos] ) {
02306 delete transport->cargo[ pos ] ;
02307 transport->cargo[ pos ] = NULL;
02308 }
02309 }
02310
02311 void tvehiclecargo :: checkforadditionalkeys ( tkey ch )
02312 {
02313 if ( transport->cargo.size() > cursorpos && transport->cargo[cursorpos] ) {
02314
02315 if ( ch == ct_p )
02316 changeunitvalues( transport->cargo[ cursorpos ] );
02317 if ( ch == ct_c )
02318 cargoEditor( transport->cargo[ cursorpos ] );
02319
02320 if ( ch == ct_c + ct_stp )
02321 if ( transport->cargo[ cursorpos ] ) {
02322 ClipBoard::Instance().clear();
02323 ClipBoard::Instance().addUnit( transport->cargo[ cursorpos ] );
02324 }
02325 }
02326 if ( ch == ct_v + ct_stp ) {
02327 Vehicle* veh = ClipBoard::Instance().pasteUnit();
02328 if ( transport->vehicleFit( veh )) {
02329 transport->addToCargo( veh );
02330 redraw();
02331 } else
02332 delete veh;
02333 }
02334 }
02335
02336
02337 void tvehiclecargo :: finish ( int cancel )
02338 {
02339 if ( cancel )
02340 tus.restore();
02341 }
02342
02343
02344 #endif
02345
02346 #if 0
02347
02348 class SelectFromContainer : public tladeraum {
02349 protected:
02350 ContainerBase* transport;
02351 virtual const char* getinfotext ( int pos );
02352 virtual void additem ( void );
02353 virtual void removeitem ( int pos );
02354 virtual void checkforadditionalkeys ( tkey ch );
02355 void displaysingleitem ( int pos, int x, int y );
02356 virtual void finish ( int cancel );
02357
02358 public:
02359 SelectFromContainer ( ContainerBase* unit ) : transport ( unit ), unit(NULL) {};
02360 void init ( );
02361 Vehicle* unit;
02362
02363
02364 };
02365
02366
02367 const char* SelectFromContainer :: getinfotext ( int pos )
02368 {
02369 if ( transport->loading[ pos ] )
02370 if ( !transport->loading[ pos ]->name.empty() )
02371 return transport->loading[ pos ]->name.c_str();
02372 else if ( !transport->loading[ pos ]->typ->name.empty() )
02373 return transport->loading[ pos ]->typ->name.c_str();
02374 else
02375 return transport->loading[ pos ]->typ->description.c_str();
02376 return NULL;
02377 }
02378
02379
02380 void SelectFromContainer :: init ( )
02381 {
02382 tladeraum::init ( "select unit" );
02383 }
02384
02385 void SelectFromContainer :: displaysingleitem ( int pos, int x, int y )
02386 {
02387 if ( transport->loading[ pos ] )
02388 transport->loading[ pos ]->typ->paint( getActiveSurface(), SPoint( x, y), farbwahl );
02389 }
02390
02391 void SelectFromContainer :: additem ( void )
02392 {
02393 }
02394
02395 void SelectFromContainer :: removeitem ( int pos )
02396 {
02397 }
02398
02399 void SelectFromContainer :: checkforadditionalkeys ( tkey ch )
02400 {
02401 if ( transport->loading[ cursorpos ] ) {
02402 if ( ch == ct_c )
02403 unit = selectUnitFromContainer( transport->loading[ cursorpos ] );
02404
02405 if ( ch == ct_enter || ch == ct_space )
02406 if ( transport->loading[ cursorpos ] )
02407 unit = transport->loading[ cursorpos ];
02408
02409 if ( unit )
02410 action = 1;
02411 }
02412 }
02413
02414
02415 void SelectFromContainer :: finish ( int cancel )
02416 {
02417 }
02418
02419 #endif
02420
02421 Vehicle* selectUnitFromContainer( ContainerBase* container )
02422 {
02423 #if 0
02424 SelectFromContainer sfc ( container );
02425 sfc.init();
02426 sfc.run();
02427 sfc.done();
02428 return sfc.unit;
02429 #endif
02430 return NULL;
02431 }
02432
02433
02434
02435
02436
02437 #if 0
02438
02439 class tbuildingcargoprod : public tladeraum {
02440 TemporaryContainerStorage tus;
02441 protected:
02442 Building* building;
02443 void finish ( int cancel );
02444 public:
02445 tbuildingcargoprod ( Building* bld ) : tus ( bld, true ), building ( bld ) {};
02446 };
02447
02448
02449 void tbuildingcargoprod :: finish ( int cancel )
02450 {
02451 if ( cancel )
02452 tus.restore();
02453 }
02454 #endif
02455 #if 0
02456 class tbuildingcargo : public tbuildingcargoprod {
02457 protected:
02458 virtual const char* getinfotext ( int pos );
02459 virtual void additem ( void );
02460 virtual void removeitem ( int pos );
02461 virtual void checkforadditionalkeys ( tkey ch );
02462 void displaysingleitem ( int pos, int x, int y );
02463 public:
02464 tbuildingcargo ( Building* bld ) : tbuildingcargoprod ( bld ) {};
02465 };
02466
02467
02468
02469 void tbuildingcargo :: displaysingleitem ( int pos, int x, int y )
02470 {
02471 if ( building->loading[ pos ] )
02472 building->loading[ pos ]->typ->paint( getActiveSurface(), SPoint( x, y), farbwahl );
02473 }
02474
02475 void tbuildingcargo :: additem ( void )
02476 {
02477 selcargo ( building );
02478 }
02479
02480 void tbuildingcargo :: removeitem ( int pos )
02481 {
02482 if ( building->loading[ pos ] ) {
02483 delete building->loading[ pos ] ;
02484 building->loading[ pos ] = NULL;
02485 }
02486 }
02487
02488 void tbuildingcargo :: checkforadditionalkeys ( tkey ch )
02489 {
02490 if ( building->loading[ cursorpos ] ) {
02491 if ( ch == ct_p )
02492 changeunitvalues( building->loading[ cursorpos ] );
02493 if ( ch == ct_c )
02494 unit_cargo( building->loading[ cursorpos ] );
02495
02496 if ( ch == ct_c + ct_stp )
02497 if ( building->loading[ cursorpos ] ) {
02498 ClipBoard::Instance().clear();
02499 ClipBoard::Instance().addUnit( building->loading[ cursorpos ] );
02500 }
02501 }
02502 if ( ch == ct_v + ct_stp ) {
02503 Vehicle* veh = ClipBoard::Instance().pasteUnit();
02504 if ( building->vehicleFit( veh ))
02505 for ( int i = 0; i < 32; i++ )
02506 if ( !building->loading[i] ) {
02507 veh->convert( getFirstBit(building->color) );
02508 building->loading[i] = veh;
02509 redraw();
02510 return;
02511 }
02512 delete veh;
02513 }
02514 }
02515
02516 const char* tbuildingcargo :: getinfotext ( int pos )
02517 {
02518 if ( building->loading[ pos ] )
02519 if ( !building->loading[ pos ]->name.empty() )
02520 return building->loading[ pos ]->name.c_str();
02521 else if ( !building->loading[ pos ]->typ->name.empty() )
02522 return building->loading[ pos ]->typ->name.c_str();
02523 else
02524 return building->loading[ pos ]->typ->description.c_str();
02525 return NULL;
02526 }
02527
02528
02529 void building_cargo( Building* bld )
02530 {
02531 if ( bld ) {
02532 tbuildingcargo laderaum ( bld );
02533 laderaum.init( "cargo" );
02534 laderaum.run();
02535 laderaum.done();
02536 }
02537 }
02538
02539
02540
02541
02542
02543 class tbuildingproduction : public tbuildingcargoprod {
02544 protected:
02545 virtual const char* getinfotext ( int pos );
02546 virtual void additem ( void );
02547 virtual void removeitem ( int pos );
02548 void displaysingleitem ( int pos, int x, int y );
02549 public:
02550 tbuildingproduction ( Building* bld ) : tbuildingcargoprod ( bld ) {};
02551 };
02552
02553 void tbuildingproduction :: displaysingleitem ( int pos, int x, int y )
02554 {
02555 if ( building->unitProduction[ pos ] )
02556 building->unitProduction[ pos ]->paint( getActiveSurface(), SPoint ( x, y), farbwahl );
02557 }
02558
02559 void tbuildingproduction :: additem ( void )
02560 {
02561 selbuildingproduction ( building );
02562 }
02563
02564 void tbuildingproduction :: removeitem ( int pos )
02565 {
02566 building->unitProduction[ pos ] = NULL;
02567 }
02568
02569 const char* tbuildingproduction :: getinfotext ( int pos )
02570 {
02571 if ( building->unitProduction[ pos ] )
02572 if ( !building->unitProduction[ pos ]->name.empty() )
02573 return building->unitProduction[ pos ]->name.c_str();
02574 else
02575 return building->unitProduction[ pos ]->description.c_str();
02576 return NULL;
02577 }
02578
02579 bool isNull(const VehicleType* v ) {
02580 return !v;
02581 };
02582 #endif
02583
02584
02585 void movebuilding ( void )
02586 {
02587 warningMessage("sorry, not implemented yet in ASC2!");
02588 #if 0
02589 mapsaved = false;
02590 MapField* fld = getactfield();
02591 if ( fld->vehicle ) {
02592 Vehicle* v = fld->vehicle;
02593 fld->vehicle = NULL;
02594
02595 int x = v->xpos;
02596 int y = v->ypos;
02597 int res2 = -1;
02598 do {
02599 res2 = selectfield ( &x, &y );
02600 if ( res2 > 0 ) {
02601 if ( getfield(x,y)->vehicle || getfield(x,y)->vehicle || !terrainaccessible(getfield(x,y),v)) {
02602 displaymessage ( "you cannot place the vehicle here", 1 );
02603 res2 = -1;
02604 } else {
02605 getfield(x,y)->vehicle = v;
02606 v->setnewposition( x, y );
02607 }
02608 }
02609 } while ( res2 < 0 );
02610 displaymap();
02611
02612 }
02613 if ( fld->building ) {
02614 Building* bld = fld->building;
02615
02616 bld->unchainbuildingfromfield ();
02617
02618 MapCoordinate mc = bld->getEntry();
02619 MapCoordinate oldPosition = mc;
02620 int res2 = -1;
02621 do {
02622 res2 = selectfield ( &mc.x, &mc.y );
02623 if ( res2 > 0 ) {
02624 int res = bld->chainbuildingtofield ( mc );
02625 if ( res ) {
02626 displaymessage ( "you cannot place the building here", 1 );
02627 res2 = -1;
02628 }
02629 }
02630 } while ( res2 < 0 );
02631 if ( res2 == 0 ) {
02632 if ( bld->chainbuildingtofield ( oldPosition ))
02633 displaymessage ( "severe inconsistency in movebuilding !", 1 );
02634 }
02635 displaymap();
02636 }
02637 #endif
02638 }
02639
02640
02641 class SelectUnitSetFilter : public ASC_PG_Dialog {
02642
02643 PG_ListBox* listbox;
02644
02645 PG_Button* okButton;
02646 vector<PG_ListBoxItem*> items;
02647
02648 public:
02649 SelectUnitSetFilter() : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 300, 500 ), "Visible UnitSet Filter" ) {
02650
02651 listbox = (new MultiListBox( this, PG_Rect( 10, 30, Width()-20, Height()-80)))->getListBox();
02652
02653
02654 for ( int i = 0; i < ItemFiltrationSystem::itemFilters.size(); i++ ) {
02655 PG_ListBoxItem* item = new PG_ListBoxItem( listbox, 20, ItemFiltrationSystem::itemFilters[i]->name );
02656 items.push_back( item );
02657 item->Select( !ItemFiltrationSystem::itemFilters[i]->isActive() );
02658 }
02659
02660 okButton = AddStandardButton( "OK" );
02661 okButton->sigClick.connect( SigC::slot( *this, &SelectUnitSetFilter::ok ));
02662 };
02663
02664 bool ok() {
02665 for ( int i = 0; i < items.size(); ++i )
02666 ItemFiltrationSystem::itemFilters[i]->setActive( !items[i]->IsSelected() );
02667
02668 QuitModal();
02669 return true;
02670 }
02671
02672 bool eventKeyDown(const SDL_KeyboardEvent* key) {
02673
02674 if ( key->keysym.sym == SDLK_RETURN )
02675 return ok();
02676
02677 if ( key->keysym.sym == SDLK_ESCAPE ) {
02678 QuitModal();
02679 return true;
02680 }
02681
02682 if ( key->keysym.sym == 'a' ) {
02683 for ( vector<PG_ListBoxItem*>::const_iterator i = items.begin(); i != items.end(); ++i )
02684 (*i)->Select( true );
02685 listbox->Update();
02686 return true;
02687 }
02688
02689 if ( key->keysym.sym == 'n' ) {
02690 for ( vector<PG_ListBoxItem*>::const_iterator i = items.begin(); i != items.end(); ++i )
02691 (*i)->Select( false );
02692
02693 listbox->Update();
02694 return true;
02695 }
02696
02697 return false;
02698 }
02699 };
02700
02701
02702 void selectunitsetfilter ( void )
02703 {
02704 if ( ItemFiltrationSystem::itemFilters.size() > 0 ) {
02705 SelectUnitSetFilter susf;
02706 susf.Show();
02707 susf.RunModal();
02708
02709 filtersChangedSignal();
02710 } else
02711 displaymessage ( " no Filters defined !", 1 );
02712 }
02713
02714
02715
02716 class UnitTypeTransformation {
02717
02718 class UnitSetSelection : public tstringselect {
02719 public :
02720 virtual void setup(void);
02721 virtual void buttonpressed(int id);
02722 virtual void run(void);
02723 virtual void get_text(int nr);
02724 };
02725 class TranslationTableSelection : public tstringselect {
02726 int unitsetnum;
02727 public :
02728 virtual void setup( void );
02729 void setup2 ( int _unitset ) {
02730 unitsetnum = _unitset;
02731 };
02732 virtual void buttonpressed(int id);
02733 virtual void run(void);
02734 virtual void get_text(int nr);
02735 };
02736
02737 int unitstransformed;
02738 int unitsnottransformed;
02739
02740 VehicleType* transformvehicletype ( const VehicleType* type, int unitsetnum, int translationnum );
02741 void transformvehicle ( Vehicle* veh, int unitsetnum, int translationnum );
02742 set<int> vehicleTypesNotTransformed;
02743 public:
02744 void run ( void );
02745 } ;
02746
02747
02748 void UnitTypeTransformation :: UnitSetSelection::setup(void)
02749 {
02750 action = 0;
02751 title = "Select UnitSet";
02752 numberoflines = unitSets.size();
02753 ey = ysize - 60;
02754 addbutton("~D~one",20,ysize - 40,170,ysize - 20,0,1,202,true);
02755 addkey(202,ct_enter);
02756 addbutton("~C~ancel",190,ysize - 40,340,ysize - 20,0,1,203,true);
02757 addkey(203,ct_esc);
02758 }
02759
02760 void UnitTypeTransformation :: UnitSetSelection::buttonpressed(int id)
02761 {
02762 tstringselect::buttonpressed(id);
02763 switch (id) {
02764 case 202:
02765 case 203:
02766 action = id - 200;
02767 break;
02768 }
02769 }
02770
02771 void UnitTypeTransformation :: UnitSetSelection::get_text(int nr)
02772 {
02773 strcpy(txt,unitSets[nr]->name.c_str() );
02774 }
02775
02776 void UnitTypeTransformation :: UnitSetSelection::run(void)
02777 {
02778 do {
02779 tstringselect::run();
02780 } while ( ! ( action > 0 || (msel == 1)) );
02781
02782 if ( action == 3)
02783 redline = -1;
02784 }
02785
02786
02787
02788 void UnitTypeTransformation :: TranslationTableSelection::setup( void )
02789 {
02790 action = 0;
02791 title = "Select Transformation Table";
02792 numberoflines = unitSets[unitsetnum]->transtab.size();
02793 ey = ysize - 60;
02794 addbutton("~D~one",20,ysize - 40,170,ysize - 20,0,1,202,true);
02795 addkey(202,ct_enter);
02796 addbutton("~C~ancel",190,ysize - 40,340,ysize - 20,0,1,203,true);
02797 addkey(203,ct_esc);
02798 }
02799
02800 void UnitTypeTransformation :: TranslationTableSelection::buttonpressed(int id)
02801 {
02802 tstringselect::buttonpressed(id);
02803 switch (id) {
02804 case 202:
02805 case 203:
02806 action = id-200;
02807 break;
02808 }
02809 }
02810
02811 void UnitTypeTransformation :: TranslationTableSelection::get_text(int nr)
02812 {
02813 strcpy(txt, unitSets[unitsetnum]->transtab[nr]->name.c_str() );
02814 }
02815
02816 void UnitTypeTransformation :: TranslationTableSelection::run(void)
02817 {
02818 do {
02819 tstringselect::run();
02820 } while ( ! ( action > 0 || (msel == 1)) );
02821
02822 if ( action == 3)
02823 redline = -1;
02824 }
02825
02826 VehicleType* UnitTypeTransformation :: transformvehicletype ( const VehicleType* type, int unitsetnum, int translationnum )
02827 {
02828 for ( int i = 0; i < unitSets[unitsetnum]->transtab[translationnum]->translation.size(); i++ )
02829 if ( unitSets[unitsetnum]->transtab[translationnum]->translation[i].from == type->id ) {
02830 VehicleType* tp = vehicleTypeRepository.getObject_byID ( unitSets[unitsetnum]->transtab[translationnum]->translation[i].to );
02831 if ( tp )
02832 return tp;
02833 }
02834
02835 vehicleTypesNotTransformed.insert( type->id );
02836
02837 return NULL;
02838 }
02839
02840 void UnitTypeTransformation ::transformvehicle ( Vehicle* veh, int unitsetnum, int translationnum )
02841 {
02842 for ( ContainerBase::Cargo::const_iterator i = veh->getCargo().begin(); i != veh->getCargo().end(); ++i )
02843 if ( *i )
02844 transformvehicle ( *i, unitsetnum, translationnum );
02845
02846 VehicleType* nvt = transformvehicletype ( veh->typ, unitsetnum, translationnum );
02847 if ( !nvt ) {
02848 unitsnottransformed++;
02849 return;
02850 }
02851 veh->transform ( nvt );
02852
02853 unitstransformed++;
02854 }
02855
02856
02857 void UnitTypeTransformation :: run ( void )
02858 {
02859 UnitSetSelection uss;
02860 uss.init();
02861 uss.run();
02862 uss.done();
02863
02864 int unitsetnum = uss.redline;
02865 if ( unitsetnum == -1 )
02866 return;
02867
02868 TranslationTableSelection tss;
02869 tss.setup2( unitsetnum );
02870 tss.init();
02871 tss.run();
02872 tss.done();
02873
02874 int translationsetnum = tss.redline;
02875 if ( translationsetnum == -1 || translationsetnum == 255 )
02876 return;
02877
02878 unitstransformed = 0;
02879 unitsnottransformed = 0;
02880
02881
02882 for ( int y = 0; y < actmap->ysize; y++ )
02883 for ( int x = 0; x < actmap->xsize; x++ ) {
02884 MapField* fld = getfield ( x, y );
02885 if ( fld->vehicle )
02886 transformvehicle ( fld->vehicle, unitsetnum, translationsetnum );
02887 if ( fld->building && (fld->bdt & getTerrainBitType(cbbuildingentry) ).any() ) {
02888 for ( ContainerBase::Cargo::const_iterator i = fld->building->getCargo().begin(); i != fld->building->getCargo().end(); ++i )
02889 if ( *i )
02890 transformvehicle ( *i, unitsetnum, translationsetnum );
02891
02892 ContainerBase::Production prod = fld->building->getProduction();
02893 for ( ContainerBase::Production::iterator j = prod.begin(); j != prod.end(); ++j )
02894 if ( *j && transformvehicletype ( *j, unitsetnum, translationsetnum ) ) {
02895 *j = transformvehicletype ( *j, unitsetnum, translationsetnum );
02896 ++unitstransformed;
02897 }
02898
02899 fld->building->setProductionLines( prod );
02900 }
02901 }
02902
02903 if ( vehicleTypesNotTransformed.size() ) {
02904 ASCString s = "The following vehicles could not be transformed: ";
02905 for ( set<int>::const_iterator i = vehicleTypesNotTransformed.begin(); i != vehicleTypesNotTransformed.end(); ++i ) {
02906 s += "\n ID ";
02907 s += ASCString::toString( *i );
02908 s += " : ";
02909 VehicleType* vt = vehicleTypeRepository.getObject_byID ( *i );
02910 if ( !vt-> name.empty() )
02911 s += vt->name;
02912 else
02913 s += vt->description;
02914 }
02915
02916 s += "\n";
02917 s += strrr ( unitstransformed );
02918 s += " units were transformed\n";
02919 s += strrr ( unitsnottransformed );
02920 s += " units were NOT transformed\n (production included)";
02921
02922 tviewanytext vat;
02923 vat.init ( "warningMessage", s.c_str() );
02924 vat.run();
02925 vat.done();
02926 } else
02927 displaymessage ( "All units were transformed !\ntotal number: %d", 3, unitstransformed );
02928
02929
02930 }
02931
02932 void unitsettransformation( void )
02933 {
02934 UnitTypeTransformation utt;
02935 utt.run();
02936 }
02937
02938
02939 void MapSwitcher::deleteMaps()
02940 {
02941 delete actmap;
02942 actmap = NULL;
02943 toggle();
02944 delete actmap;
02945 actmap = NULL;
02946 }
02947
02948 void MapSwitcher :: toggle ( )
02949 {
02950 maps[active].map = actmap;
02951 maps[active].changed = !mapsaved;
02952
02953 if ( getMainScreenWidget() ) {
02954 MapDisplayPG* md = getMainScreenWidget()->getMapDisplay();
02955 if ( md )
02956 maps[active].windowpos = md->upperLeftCorner();
02957 }
02958
02959 active = !active;
02960
02961
02962
02963 actmap = maps[active].map;
02964 mapsaved = !maps[active].changed;
02965
02966
02967 if ( getMainScreenWidget() ) {
02968 MapDisplayPG* md = getMainScreenWidget()->getMapDisplay();
02969 if ( md )
02970 md->cursor.goTo( actmap->getCursor(), maps[active].windowpos );
02971 }
02972
02973 displaymap();
02974 viewChanged();
02975
02976 int x,y;
02977 SDL_Event ev;
02978 while ( PG_Application::GetEventSupplier()->GetMouseState(x,y))
02979 PG_Application::GetEventSupplier()->WaitEvent (&ev);
02980 }
02981
02982 string MapSwitcher :: getName ()
02983 {
02984 const char* name[2] = { "primary", "secondary" };
02985 string s;
02986 s = name[active];
02987
02988 if ( actmap )
02989 if ( !actmap->preferredFileNames.mapname[0].empty() ) {
02990 s += " ( ";
02991 s += actmap->preferredFileNames.mapname[0];
02992 s += " ) ";
02993 }
02994
02995 return s;
02996 }
02997
02998 MapSwitcher::Action MapSwitcher :: getDefaultAction ( )
02999 {
03000 if ( active )
03001 return select;
03002 else
03003 return set;
03004 }
03005
03006
03007 MapSwitcher mapSwitcher;
03008
03009
03010 VehicleType* transform( int id, const vector<int>& translation )
03011 {
03012 for ( int i = 0; i < translation.size()/2; i++ )
03013 if ( id == translation[i*2] )
03014 return vehicleTypeRepository.getObject_byID ( translation[i*2+1] );
03015 return NULL;
03016 }
03017
03018 void transformMap ( )
03019 {
03020
03021 ASCString filename = selectFile( "*.ascmapxlat", true );
03022
03023 if ( filename.empty() )
03024 return;
03025
03026
03027 vector<int> terraintranslation;
03028 vector<int> objecttranslation;
03029 vector<int> terrainobjtranslation;
03030 vector<int> buildingtranslation;
03031 vector<int> vehicletranslation;
03032 vector<int> o2ot_translation;
03033 vector<ASCString> techAdapterTranslation;
03034
03035 try {
03036 tnfilestream s ( filename, tnstream::reading );
03037
03038 TextFormatParser tfp ( &s );
03039 TextPropertyGroup* tpg = tfp.run();
03040
03041 PropertyReadingContainer pc ( "maptranslation", tpg );
03042
03043 pc.addIntegerArray ( "TerrainTranslation", terraintranslation );
03044 pc.addIntegerArray ( "TerrainObjTranslation", terrainobjtranslation );
03045 pc.addIntegerArray ( "ObjectTranslation", objecttranslation );
03046 pc.addIntegerArray ( "BuildingTranslation", buildingtranslation );
03047 if ( pc.find( "VehicleTranslation" ))
03048 pc.addIntegerArray ( "VehicleTranslation", vehicletranslation );
03049
03050 if ( pc.find( "Object2ObjTerrainTranslation" ))
03051 pc.addIntegerArray( "Object2ObjTerrainTranslation", o2ot_translation );
03052
03053 if ( pc.find( "TechAdapterTranslation" ))
03054 pc.addStringArray( "TechAdapterTranslation", techAdapterTranslation );
03055
03056 delete tpg;
03057 }
03058 catch ( ParsingError err ) {
03059 displaymessage ( "Error parsing file : " + err.getMessage() , 1 );
03060 return;
03061 }
03062 catch ( ASCexception ) {
03063 displaymessage ( "Error reading file " + filename , 1 );
03064 return;
03065 }
03066
03067 if ( terraintranslation.size() % 2 ) {
03068 displaymessage ( "Map Translation : terraintranslation - Invalid number of entries ", 1);
03069 return;
03070 }
03071
03072 if ( terrainobjtranslation.size() % 3 ) {
03073 displaymessage ( "Map Translation : terrainobjtranslation - Invalid number of entries ", 1);
03074 return;
03075 }
03076
03077 if ( objecttranslation.size() % 2 ) {
03078 displaymessage ( "Map Translation : objecttranslation - Invalid number of entries ", 1);
03079 return;
03080 }
03081
03082 if ( buildingtranslation.size() % 2 ) {
03083 displaymessage ( "Map Translation : buildingtranslation - Invalid number of entries ", 1);
03084 return;
03085 }
03086
03087 if ( vehicletranslation.size() % 2 ) {
03088 displaymessage ( "Map Translation : VehicleTranslation - Invalid number of entries ", 1);
03089 return;
03090 }
03091
03092 if ( o2ot_translation.size() % 3 ) {
03093 displaymessage ( "Map Translation : Object2ObjTerrainTranslation - Invalid number of entries ", 1);
03094 return;
03095 }
03096
03097 if ( techAdapterTranslation.size() % 2 ) {
03098 displaymessage ( "Map Translation : TechAdapterTranslation - Invalid number of entries ", 1);
03099 return;
03100 }
03101
03102
03103 for ( int y = 0; y < actmap->ysize; y++ )
03104 for ( int x = 0; x < actmap->xsize; x++ ) {
03105 MapField* fld = actmap->getField ( x, y );
03106 for ( int i = 0; i < terraintranslation.size()/2; i++ )
03107 if ( fld->typ->terraintype->id == terraintranslation[i*2] ) {
03108 TerrainType* tt = terrainTypeRepository.getObject_byID ( terraintranslation[i*2+1] );
03109 if ( tt ) {
03110 TerrainType::Weather* tw = tt->weather[fld->getWeather()];
03111 if ( !tw )
03112 tw = tt->weather[0];
03113 fld->typ = tw;
03114 fld->setparams();
03115 }
03116 }
03117
03118 for ( int i = 0; i < terrainobjtranslation.size()/3; i++ )
03119 if ( fld->typ->terraintype->id == terrainobjtranslation[i*3] ) {
03120 TerrainType* tt = terrainTypeRepository.getObject_byID ( terrainobjtranslation[i*3+1] );
03121 if ( tt ) {
03122 TerrainType::Weather* tw = tt->weather[fld->getWeather()];
03123 if ( !tw )
03124 tw = tt->weather[0];
03125 fld->typ = tw;
03126 fld->addobject ( objectTypeRepository.getObject_byID ( terrainobjtranslation[i*3+2] ), -1, true );
03127 fld->setparams();
03128 }
03129 }
03130
03131
03132 for ( int j = 0; j < fld->objects.size(); ++j )
03133 for ( int i = 0; i < objecttranslation.size() / 2; i++ )
03134 if ( fld->objects[j].typ->id == objecttranslation[i*2] ) {
03135 ObjectType* ot = objectTypeRepository.getObject_byID ( objecttranslation[i*2+1] );
03136 if ( ot ) {
03137 fld->objects[j].typ = ot;
03138 fld->sortobjects();
03139 fld->setparams();
03140 j = -1;
03141 break;
03142 } else {
03143 fld->removeObject( fld->objects[j].typ, true );
03144 j = -1;
03145 break;
03146 }
03147 }
03148 for ( int b = 0; b < buildingtranslation.size()/2; ++b )
03149 if ( (fld->bdt & getTerrainBitType(cbbuildingentry)).any() && fld->building && fld->building->typ->id == buildingtranslation[b*2] ) {
03150 BuildingType* newtype = buildingTypeRepository.getObject_byID ( buildingtranslation[b*2+1] );
03151 if ( newtype ) {
03152 Building* bld = fld->building;
03153 const BuildingType* orgtype = fld->building->typ;
03154 MapCoordinate orgpos = bld->getEntry();
03155 MapCoordinate pos = orgpos;
03156 bld->unchainbuildingfromfield();
03157 bld->typ = newtype;
03158 int iteration = 0;
03159 enum { trying, success, failed } state = trying;
03160 do {
03161 if ( bld->chainbuildingtofield( pos )) {
03162 pos = getNeighbouringFieldCoordinate( orgpos, iteration );
03163 } else
03164 state = success;
03165
03166 ++iteration;
03167
03168 if ( iteration > 6 && state != success ) {
03169 state = failed;
03170 bld->typ = orgtype;
03171 bld->chainbuildingtofield( orgpos );
03172 }
03173 } while ( state == trying );
03174
03175 } else {
03176 delete fld->building;
03177 }
03178 }
03179
03180 for ( int j = 0; j < fld->objects.size(); ++j )
03181 for ( int i = 0; i < o2ot_translation.size() / 3; i++ )
03182 if ( fld->objects[j].typ->id == o2ot_translation[i*3] ) {
03183 fld->removeObject( fld->objects[j].typ, true );
03184 TerrainType* tt = terrainTypeRepository.getObject_byID ( o2ot_translation[i*3+2] );
03185 if ( tt ) {
03186 TerrainType::Weather* tw = tt->weather[fld->getWeather()];
03187 if ( !tw )
03188 tw = tt->weather[0];
03189 fld->typ = tw;
03190 }
03191 ObjectType* ot = objectTypeRepository.getObject_byID ( o2ot_translation[i*3+1] );
03192 if ( ot )
03193 fld->addobject ( ot, -1, true );
03194
03195
03196 fld->setparams();
03197
03198 j = -1;
03199 break;
03200 }
03201 }
03202
03203
03204
03205 for ( int p = 0; p < actmap->getPlayerCount(); ++p ) {
03206 Player::VehicleList::iterator di = actmap->getPlayer(p).vehicleList.begin();
03207 while ( di != actmap->getPlayer(p).vehicleList.end() ) {
03208 bool found = false;
03209 for ( int i = 0; i < vehicletranslation.size()/2; ++i )
03210 if ( (*di)->typ->id == vehicletranslation[i*2] && vehicletranslation[i*2+1] <= 0 ) {
03211 delete *di;
03212 found = true;
03213 break;
03214 }
03215 if ( found )
03216 di = actmap->getPlayer(p).vehicleList.begin();
03217 else
03218 ++di;
03219 }
03220
03221
03222
03223 for ( Player::VehicleList::iterator i = actmap->getPlayer(p).vehicleList.begin(); i != actmap->getPlayer(p).vehicleList.end(); ++i) {
03224 (*i)->transform( transform( (*i)->typ->id, vehicletranslation));
03225
03226 ContainerBase::Production prod = (*i)->getProduction();
03227 for ( ContainerBase::Production::iterator j = prod.begin(); j != prod.end(); ++j )
03228 if ( *j && transform((*j)->id, vehicletranslation) )
03229 *j = transform((*j)->id, vehicletranslation);
03230
03231 (*i)->setProductionLines( prod );
03232 }
03233 for ( Player::BuildingList::iterator i = actmap->getPlayer(p).buildingList.begin(); i != actmap->getPlayer(p).buildingList.end(); ++i) {
03234 ContainerBase::Production prod = (*i)->getProduction();
03235 for ( ContainerBase::Production::iterator j = prod.begin(); j != prod.end(); ++j )
03236 if ( *j && transform((*j)->id, vehicletranslation) )
03237 *j = transform((*j)->id, vehicletranslation);
03238
03239 (*i)->setProductionLines( prod );
03240 }
03241
03242 Research& r = actmap->getPlayer(p).research;
03243 for ( vector<ASCString>::iterator tat = techAdapterTranslation.begin(); tat != techAdapterTranslation.end(); ) {
03244 ASCString from = *(tat++);
03245 ASCString to = *(tat++);
03246
03247 vector<ASCString> triggeredAdapters( r.triggeredTechAdapter.begin(), r.triggeredTechAdapter.end() );
03248 replace( triggeredAdapters.begin(), triggeredAdapters.end(), from, to );
03249 r.triggeredTechAdapter.clear();
03250 r.triggeredTechAdapter.insert( triggeredAdapters.begin(), triggeredAdapters.end() );
03251
03252 replace( r.predefinedTechAdapter.begin(), r.predefinedTechAdapter.end(), from, to );
03253 }
03254
03255 }
03256
03257
03258
03259
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277
03278 calculateallobjects( actmap );
03279 displaymap();
03280 }
03281
03282
03283 class EditArchivalInformation : public tdialogbox {
03284 GameMap* gamemap;
03285 char maptitle[10000];
03286 char author[10000];
03287 ASCString description;
03288 char tags[10000];
03289 char requirements[10000];
03290 int action;
03291 public:
03292 EditArchivalInformation ( GameMap* map );
03293 void init();
03294 void run();
03295 void buttonpressed ( int id );
03296 };
03297
03298
03299 EditArchivalInformation :: EditArchivalInformation ( GameMap* map ) : gamemap ( map )
03300 {
03301 strcpy ( maptitle, map->maptitle.c_str() );
03302 strcpy ( author, map->archivalInformation.author.c_str() );
03303 description = map->archivalInformation.description;
03304 strcpy ( tags, map->archivalInformation.tags.c_str() );
03305 strcpy ( requirements, map->archivalInformation.requirements.c_str() );
03306 }
03307
03308 void EditArchivalInformation::init()
03309 {
03310 tdialogbox::init();
03311 title = "Edit Archival Information";
03312 xsize = 600;
03313 ysize = 410;
03314 action = 0;
03315
03316
03317 addbutton("~T~itle",20,70,xsize - 20,90,1,1,10,true);
03318 addeingabe(10,maptitle,0,10000);
03319
03320 addbutton("~A~uthor",20,120,xsize - 20,140,1,1,11,true);
03321 addeingabe(11,author,0,10000);
03322
03323 addbutton("Ta~g~s",20,170,xsize - 20,190,1,1,12,true);
03324 addeingabe(12,tags,0,10000);
03325
03326 addbutton("~R~equirements ( see http://asc-hq.sf.net/req.php for possible values)",20,220,xsize - 20,240,1,1,13,true);
03327 addeingabe(13,requirements,0,10000);
03328
03329
03330 addbutton("Edit ~D~escription",20,ysize - 70,170,ysize - 50,0,1,14,true);
03331
03332 addbutton("~O~k",20,ysize - 40,xsize/2-10,ysize - 20,0,1,1,true);
03333 addkey(1,ct_enter);
03334 addbutton("~C~ancel",xsize/2+10,ysize - 40,xsize-20,ysize - 20,0,1,2,true);
03335 addkey(2,ct_esc);
03336
03337 buildgraphics();
03338 }
03339
03340 void EditArchivalInformation :: buttonpressed ( int id )
03341 {
03342 switch ( id ) {
03343 case 14: {
03344 MultilineEdit mle ( description, "Map Description" );
03345 mle.init();
03346 mle.run();
03347 mle.done();
03348 break;
03349 }
03350 case 1:
03351 gamemap->archivalInformation.author = author;
03352 gamemap->archivalInformation.tags = tags;
03353 gamemap->archivalInformation.requirements = requirements;
03354 gamemap->archivalInformation.description = description;
03355 gamemap->maptitle = maptitle;
03356 mapsaved = false;
03357 case 2:
03358 action = id;
03359 }
03360 }
03361
03362 void EditArchivalInformation :: run ()
03363 {
03364 do {
03365 tdialogbox::run();
03366 } while ( action == 0);
03367 }
03368
03369
03370 void editArchivalInformation()
03371 {
03372 EditArchivalInformation eai ( actmap );
03373 eai.init();
03374 eai.run();
03375 eai.done();
03376 }
03377
03378 void resourceComparison ( )
03379 {
03380 ASCString s;
03381 for ( int i = 0; i < 9; i++ ) {
03382 s += ASCString("player ") + strrr ( i ) + " : ";
03383 Resources plus;
03384 Resources have;
03385 for ( Player::BuildingList::iterator b = actmap->player[i].buildingList.begin(); b != actmap->player[i].buildingList.end(); ++b ) {
03386 if ( actmap->_resourcemode == 0 )
03387 plus += (*b)->plus;
03388 else
03389 plus += (*b)->bi_resourceplus;
03390
03391 have += (*b)->actstorage;
03392 }
03393 for ( int r = 0; r < resourceTypeNum; r++ ) {
03394 s += ASCString(resourceNames[r]) + " " + strrr ( have.resource(r)) + " +";
03395 s += strrr(plus.resource(r));
03396 s += "; ";
03397 }
03398
03399 s += "\n\n";
03400 }
03401
03402 Resources res;
03403 for ( int x = 0; x < actmap->xsize; x++)
03404 for ( int y = 0; y < actmap->ysize; y++ ) {
03405 res.material += actmap->getField(x,y)->material;
03406 res.fuel += actmap->getField(x,y)->fuel;
03407 }
03408
03409 s += "Mineral Resources: ";
03410 s += strrr(res.material );
03411 s += " Material, ";
03412 s += strrr(res.material );
03413 s += " Fuel";
03414
03415 displaymessage ( s, 3 );
03416 }
03417
03418
03419
03420
03421 void readClipboard()
03422 {
03423 ASCString filename = selectFile( ASCString(clipboardFileExtension) + ";" + oldClipboardFileExtension, true);
03424 if ( !filename.empty() ) {
03425 try {
03426 if ( patimat( oldClipboardFileExtension, filename )) {
03427 tnfilestream stream ( filename, tnstream::reading );
03428 ClipBoard::Instance().read( stream );
03429 } else {
03430 tnfilestream stream ( filename, tnstream::reading );
03431 TextFormatParser parser(&stream);
03432 PropertyReadingContainer pc ( "ClipboardInfo", parser.run() );
03433 ClipBoard::Instance().readProperties( pc );
03434 }
03435 } catch ( ASCmsgException me ) {
03436 errorMessage( "Error reading clipboard file:\n" + me.getMessage());
03437 } catch ( ... ) {
03438 errorMessage( "Error reading clipboard file" );
03439 }
03440
03441 }
03442 }
03443
03444 void saveClipboard()
03445 {
03446 ASCString filename = selectFile( clipboardFileExtension, false);
03447 if ( !filename.empty() ) {
03448 tn_file_buf_stream txtstream ( filename, tnstream::writing );
03449 PropertyWritingContainer pc ( "ClipboardInfo", txtstream );
03450 ClipBoard::Instance().writeProperties( pc );
03451 }
03452 }
03453
03454 void setweatherall ( int weather )
03455 {
03456 for (int y=0; y < actmap->ysize; y++)
03457 for (int x=0; x < actmap->xsize; x++)
03458 actmap->getField(x,y)->setWeather( weather );
03459 }
03460
03461
03462 ASCString printTech( int id )
03463 {
03464 ASCString s;
03465 s.format ( "%7d ", id );
03466 const Technology* t = technologyRepository.getObject_byID ( id );
03467 if ( t )
03468 s += t->name;
03469
03470 return s;
03471 }
03472
03473 void editResearch()
03474 {
03475 vector<ASCString> buttons;
03476 buttons.push_back ( "~A~dd" );
03477 buttons.push_back ( "~R~emove" );
03478 buttons.push_back ( "~C~lose" );
03479
03480 vector<ASCString> buttons2;
03481 buttons2.push_back ( "~A~dd" );
03482 buttons2.push_back ( "~C~ancel" );
03483
03484 vector<ASCString> buttonsP;
03485 buttonsP.push_back ( "~E~dit" );
03486 buttonsP.push_back ( "~C~lose" );
03487
03488 pair<int,int> playerRes;
03489 do {
03490 vector<ASCString> player;
03491 for ( int i = 0; i < 8; ++i )
03492 player.push_back ( ASCString ( strrr(i)) + " " + actmap->player[i].getName());
03493
03494 playerRes = chooseString ( "Choose Player", player, buttonsP );
03495 if ( playerRes.first == 0 && playerRes.second >= 0 ) {
03496 int player = playerRes.second;
03497
03498 pair<int,int> res;
03499 do {
03500 vector<int>& devTech = actmap->player[player].research.developedTechnologies;
03501 vector<ASCString> techs;
03502 map<ASCString,int> techIds;
03503 for ( int i = 0; i < devTech.size(); ++i ) {
03504 int id = devTech[i];
03505 ASCString s = printTech(id );
03506 techs.push_back ( s );
03507 techIds[s] = id;
03508 }
03509 sort (techs.begin(), techs.end() );
03510 res = chooseString ( "Available Technologies", techs, buttons );
03511 if ( res.first == 0 ) {
03512 vector<ASCString> techs;
03513 vector<int> techIds;
03514 for ( int i = 0; i < technologyRepository.getNum(); ++i ) {
03515 const Technology* t = technologyRepository.getObject_byPos(i);
03516 if ( find ( devTech.begin(), devTech.end(), t->id ) == devTech.end() )
03517 if ( !ItemFiltrationSystem::isFiltered( ItemFiltrationSystem::Technology, t->id )) {
03518 techs.push_back ( printTech ( t->id ));
03519 techIds.push_back ( t->id );
03520 }
03521 }
03522
03523 if ( techIds.empty() ) {
03524 infoMessage("No technologies found. Please review Item Filters");
03525 } else {
03526
03527 pair<int,int> r = chooseString ( "Unresearched Technologies", techs, buttons2 );
03528 if ( r.first == 0 && r.second >= 0 ) {
03529 devTech.push_back ( techIds[r.second] );
03530 }
03531 }
03532 } else if ( res.first == 1 && res.second >= 0 ) {
03533 vector<int>::iterator p = find ( devTech.begin(), devTech.end(), techIds[techs[res.second]]);
03534 devTech.erase ( p );
03535 }
03536 } while ( res.first != 2 );
03537 }
03538 } while ( playerRes.first != 1 );
03539 }
03540
03541 void editResearchPoints()
03542 {
03543 vector<ASCString> buttonsP;
03544 buttonsP.push_back ( "~E~dit" );
03545 buttonsP.push_back ( "~C~lose" );
03546
03547 pair<int,int> playerRes;
03548 do {
03549 vector<ASCString> player;
03550 for ( int i = 0; i < 8; ++i ) {
03551 ASCString s = strrr(i);
03552 player.push_back ( s + " " + actmap->player[i].getName() + " (" + strrr(actmap->player[i].research.progress) + " Points)" );
03553 }
03554
03555 playerRes = chooseString ( "Choose Player", player, buttonsP );
03556 if ( playerRes.first == 0 && playerRes.second >= 0 )
03557 actmap->player[playerRes.second].research.progress = editInt ( "Points", actmap->player[playerRes.second].research.progress );
03558
03559 } while ( playerRes.first != 1 );
03560 }
03561
03562
03563 void generateTechTree()
03564 {
03565 ASCString filename = selectFile("*.dot", false);
03566 if ( !filename.empty() ) {
03567
03568 map<ASCString,int> temptechs;
03569 for ( int i = 0; i < technologyRepository.getNum(); ++i ) {
03570 const Technology* t = technologyRepository.getObject_byPos(i);
03571 if ( !ItemFiltrationSystem::isFiltered( ItemFiltrationSystem::Technology, t->id )) {
03572 temptechs[t->name] = t->id;
03573 }
03574 }
03575
03576 vector<ASCString> techs;
03577 vector<int> techIds;
03578 for ( map<ASCString,int>::iterator i = temptechs.begin(); i != temptechs.end(); ++i ) {
03579 techs.push_back ( printTech ( i->second ));
03580 techIds.push_back ( i->second );
03581 }
03582
03583
03584
03585
03586
03587
03588
03589
03590
03591
03592
03593
03594
03595
03596
03597
03598
03599
03600
03601 vector<ASCString> buttons2;
03602 buttons2.push_back ( "~O~k" );
03603 buttons2.push_back ( "~C~ancel" );
03604
03605 bool leavesUp = choice_dlg ( "tree direction", "leaves up", "root up" ) == 1;
03606
03607 if ( leavesUp ) {
03608
03609 pair<int,int> r = chooseString ( "Choose Base Technology", techs, buttons2 );
03610 if ( r.first == 0 ) {
03611
03612
03613 bool reduce = choice_dlg ( "generate sparce tree ?", "~y~es", "~n~o" ) == 1;
03614
03615 tn_file_buf_stream f ( filename, tnstream::writing );
03616
03617 f.writeString ( "digraph \"ASC Technology Tree\" { \nnode [color=gray]\n", false );
03618
03619 for ( int i = 0; i < technologyRepository.getNum(); ++i ) {
03620 const Technology* t = technologyRepository.getObject_byPos(i);
03621 if ( !ItemFiltrationSystem::isFiltered( ItemFiltrationSystem::Technology, t->id )) {
03622 vector<int> stack;
03623 if ( t->techDependency.findInheritanceLevel( techIds[r.second], stack, techs[r.second] ) > 0 )
03624 t->techDependency.writeTreeOutput( t->name, f, reduce );
03625 }
03626
03627 }
03628
03629 ASCString stn2 = technologyRepository.getObject_byID(techIds[r.second])->name;
03630 while ( stn2.find ( "\"" ) != ASCString::npos )
03631 stn2.erase ( stn2.find ( "\"" ),1 );
03632
03633 f.writeString ( "\"" + stn2 + "\" [shape=doublecircle] \n", false );
03634 f.writeString ( "}\n", false );
03635 }
03636 } else {
03637 pair<int,int> r = chooseString ( "Choose Tip Technology", techs, buttons2 );
03638 if ( r.first == 0 ) {
03639
03640 tn_file_buf_stream f ( filename, tnstream::writing );
03641
03642 f.writeString ( "digraph \"ASC Technology Tree\" { \nnode [color=gray]\n", false );
03643
03644 const Technology* t = technologyRepository.getObject_byID(techIds[r.second]);
03645 vector<int> history;
03646 vector<pair<int,int> > blockedPrintList;
03647 if ( t )
03648 t->techDependency.writeInvertTreeOutput( t->name, f, history, blockedPrintList );
03649
03650 ASCString stn2 = technologyRepository.getObject_byID(techIds[r.second])->name;
03651 while ( stn2.find ( "\"" ) != ASCString::npos )
03652 stn2.erase ( stn2.find ( "\"" ),1 );
03653
03654 f.writeString ( "\"" + stn2 + "\" [shape=doublecircle] \n", false );
03655 f.writeString ( "}\n", false );
03656 }
03657 }
03658
03659 }
03660 }
03661
03662
03663
03664 void editTechAdapter()
03665 {
03666 vector<ASCString> buttons;
03667 buttons.push_back ( "~A~dd" );
03668 buttons.push_back ( "~R~emove" );
03669 buttons.push_back ( "~C~lose" );
03670
03671 vector<ASCString> buttons2;
03672 buttons2.push_back ( "~A~dd" );
03673 buttons2.push_back ( "~C~ancel" );
03674
03675 vector<ASCString> buttonsP;
03676 buttonsP.push_back ( "~E~dit" );
03677 buttonsP.push_back ( "~C~lose" );
03678
03679 pair<int,int> playerRes;
03680 do {
03681 vector<ASCString> player;
03682 for ( int i = 0; i < 8; ++i )
03683 player.push_back ( ASCString ( strrr(i)) + " " + actmap->player[i].getName());
03684
03685 playerRes = chooseString ( "Choose Player", player, buttonsP );
03686 if ( playerRes.first == 0 && playerRes.second >= 0) {
03687 int player = playerRes.second;
03688 editTechAdapter(actmap->player[player] );
03689 }
03690 } while ( playerRes.first != 1 );
03691 }
03692
03693
03694
03695 MapField* getactfield(void)
03696 {
03697 return actmap->getField( actmap->getCursor() );;
03698 }
03699
03700
03701 class ItemLocator : public ASC_PG_Dialog {
03702
03703 PG_LineEdit* idField;
03704 DropDownSelector* typeSelector;
03705
03706
03707 bool findUnit( ContainerBase* c, int id )
03708 {
03709 if ( !c )
03710 return false;
03711
03712 for ( ContainerBase::Cargo::const_iterator i = c->getCargo().begin(); i != c->getCargo().end(); ++i ) {
03713 if ( (*i) ) {
03714 if ( (*i)->typ->id == id )
03715 return true;
03716 if ( findUnit( *i, id ))
03717 return true;
03718 }
03719 }
03720 return false;
03721 }
03722
03723 bool ok()
03724 {
03725 int id = atoi ( idField->GetText().c_str() );
03726 if ( id != 0 ) {
03727 for ( int y = 0; y < actmap->ysize; ++y )
03728 for ( int x = 0; x < actmap->xsize; ++x ) {
03729 MapField* fld = actmap->getField(x,y);
03730 if ( fld ) {
03731 bool found = false;
03732 switch ( typeSelector->GetSelectedItemIndex () ) {
03733 case 0:
03734 if ( fld->typ->terraintype->id == id )
03735 found = true;
03736 break;
03737 case 1:
03738 if ( fld->vehicle && fld->vehicle->typ->id == id )
03739 found = true;
03740 if ( findUnit( fld->vehicle, id ))
03741 found = true;
03742 break;
03743 case 2:
03744 if ( fld->building && fld->building->typ->id == id )
03745 found = true;
03746 if ( findUnit( fld->building, id ))
03747 found = true;
03748 break;
03749 case 3:
03750 if ( fld->checkForObject( objectTypeRepository.getObject_byID( id )) )
03751 found = true;
03752 break;
03753 }
03754
03755
03756 if ( found ) {
03757 getMainScreenWidget()->getMapDisplay()->cursor.goTo(MapCoordinate(x,y));
03758 QuitModal();
03759 return true;
03760 }
03761 }
03762 }
03763
03764 }
03765 return false;
03766 }
03767
03768 bool cancel()
03769 {
03770 QuitModal();
03771 return true;
03772 }
03773
03774 public:
03775 ItemLocator() : ASC_PG_Dialog(NULL, PG_Rect(-1,-1,400,200 ), "Item Locator")
03776 {
03777 AddStandardButton("OK")->sigClick.connect( SigC::slot(*this, &ItemLocator::ok ));
03778 AddStandardButton("cancel")->sigClick.connect( SigC::slot(*this, &ItemLocator::cancel ));
03779
03780 typeSelector = new DropDownSelector(this, PG_Rect(20, 60, 150, 25 ));
03781 typeSelector->AddItem("Terrain");
03782 typeSelector->AddItem("Vehicle");
03783 typeSelector->AddItem("Building");
03784 typeSelector->AddItem("Object");
03785
03786 new PG_Label ( this, PG_Rect(20, 100, 50, 25), "ID: " );
03787 idField = new PG_LineEdit( this, PG_Rect( 70, 100, 150, 25 ));
03788 }
03789
03790 };
03791
03792
03793 void locateItemByID()
03794 {
03795 ItemLocator il;
03796 il.Show();
03797 il.RunModal();
03798 }
03799
03800
03801
03802
03803
03804
03805
03806
03807
03808 void copyVehicleData( Vehicle* source, Vehicle* target, GameMap* targetMap, int* playerTranslation )
03809 {
03810
03811 target->height = source->height;
03812 target->tank = source->getTank();
03813 target->name = source->name;
03814 target->experience = source->experience;
03815 target->damage = source->damage;
03816
03817
03818 if ( source->reactionfire.getStatus() == Vehicle::ReactionFire::off )
03819 target->reactionfire.disable();
03820 else
03821 target->reactionfire.enable();
03822
03823
03824 for ( int i=0; i<16; i++ ) target->ammo[ i ] = source->ammo[ i ];
03825
03826
03827 ContainerBase::Cargo sourceCargo = source->getCargo();
03828 for ( int i=0; i<sourceCargo.size(); i++ )
03829 {
03830 int playerID = playerTranslation[ sourceCargo[ i ]->getOwner() ];
03831 Vehicle* cargo = new Vehicle( sourceCargo[ i ]->typ, targetMap, playerID );
03832 copyVehicleData( sourceCargo[ i ], cargo, targetMap, playerTranslation );
03833 target->addToCargo( cargo );
03834 }
03835
03836 target->deleteAllProductionLines();
03837 for ( ContainerBase::Production::const_iterator i = source->getProduction().begin(); i != source->getProduction().end(); ++i )
03838 target->addProductionLine( *i );
03839
03840 }
03841
03842
03843 void copyBuildingData( Building* source, Building* target, GameMap* targetMap, int *playerTranslation, bool mirrorUnits )
03844 {
03845 for ( int i=0; i<waffenanzahl; i++ )
03846 target->ammo[ i ] = source->ammo[ i ];
03847 target->name = source->name;
03848 target->netcontrol = source->netcontrol;
03849 target->visible = source->visible;
03850
03851
03852
03853
03854 target->lastmineddist = source->lastmineddist;
03855 target->actstorage = source->actstorage;
03856 target->damage = source->damage;
03857
03858 if ( mirrorUnits )
03859 {
03860
03861 ContainerBase::Cargo sourceCargo = source->getCargo();
03862 for ( int i=0; i<sourceCargo.size(); i++ )
03863 {
03864 int playerID = playerTranslation[ sourceCargo[ i ]->getOwner() ];
03865 Vehicle* cargo = new Vehicle( sourceCargo[ i ]->typ, targetMap, playerID );
03866 copyVehicleData( sourceCargo[ i ], cargo, targetMap, playerTranslation );
03867 target->addToCargo( cargo );
03868 }
03869 }
03870
03871 target->deleteAllProductionLines();
03872 for ( ContainerBase::Production::const_iterator i = source->getProduction().begin(); i != source->getProduction().end(); ++i )
03873 target->addProductionLine( *i );
03874
03875 }
03876
03877 void copyFieldStep1( MapField* sourceField, MapField* targetField, bool mirrorTerrain, bool mirrorResources, bool mirrorWeather )
03878 {
03879 targetField->deleteeverything();
03880 while ( targetField->objects.size() > 0 )
03881 targetField->removeObject( targetField->objects[ 0 ].typ, true );
03882
03883 if ( mirrorTerrain )
03884 {
03885 targetField->typ = sourceField->typ;
03886 targetField->bdt = sourceField->bdt;
03887 }
03888
03889 if ( mirrorResources )
03890 {
03891 targetField->fuel = sourceField->fuel;
03892 targetField->material = sourceField->material;
03893 }
03894 if ( mirrorWeather ) targetField->setWeather( sourceField->getWeather() );
03895 }
03896
03897 void copyFieldStep2( MapField* sourceField, MapField* targetField, GameMap* targetMap, int *directionTranslation, int *playerTranslation, bool mirrorObjects, bool mirrorBuildings, bool mirrorUnits, bool mirrorMines )
03898 {
03899 if ( mirrorObjects )
03900 {
03901 for ( int i=0; i<sourceField->objects.size(); i++ )
03902 targetField->addobject( sourceField->objects[ i ].typ, -1, true );
03903 }
03904
03905 if ( mirrorBuildings )
03906 {
03907 if ( sourceField->building != NULL && sourceField->building->getEntryField() == sourceField )
03908 {
03909 int playerID = playerTranslation[ sourceField->building->getOwner() ];
03910 Building *newBuilding = new Building( targetMap, MapCoordinate( targetField->getx(), targetField->gety() ), sourceField->building->typ, playerID );
03911 copyBuildingData( sourceField->building, newBuilding, targetMap, playerTranslation, mirrorUnits );
03912 }
03913 }
03914
03915 if ( mirrorUnits )
03916 {
03917 if ( sourceField->vehicle != NULL )
03918 {
03919 int playerID = playerTranslation[ sourceField->vehicle->getOwner() ];
03920 targetField->vehicle = new Vehicle( sourceField->vehicle->typ, targetMap, playerID );
03921 copyVehicleData( sourceField->vehicle, targetField->vehicle, targetMap, playerTranslation );
03922 targetField->vehicle->setnewposition( targetField->getx(), targetField->gety() );
03923 targetField->vehicle->direction = directionTranslation[ int(sourceField->vehicle->direction) ];
03924 }
03925 }
03926
03927 if ( mirrorMines )
03928 {
03929 for ( int i=0; i<sourceField->mines.size(); i++ )
03930 {
03931 Mine sourceMine = sourceField->getMine( i );
03932 targetField->putmine( playerTranslation[ sourceMine.player ], sourceMine.type, sourceMine.strength );
03933 }
03934 }
03935 }
03936
03937 class MirrorMap : public tdialogbox
03938 {
03939 int mirrorUnits;
03940 int mirrorBuildings;
03941 int mirrorObjects;
03942 int mirrorMines;
03943 int mirrorResources;
03944 int mirrorWeather;
03945
03946 int playerTranslation[ 9 ];
03947
03948 bool doneMirrorMap;
03949
03950 public:
03951 void init( void );
03952 void buttonpressed ( int id );
03953 void run ( void );
03954 char checkvalue( int id, void* p );
03955
03956 protected:
03957
03958
03959 void mirrorX();
03960 void mirrorY();
03961 };
03962
03963 char MirrorMap::checkvalue( int id, void* p )
03964 {
03965 return 1;
03966 }
03967
03968 void MirrorMap::buttonpressed( int id )
03969 {
03970 tdialogbox::buttonpressed( id );
03971
03972 if ( id == 1 )
03973 doneMirrorMap = true;
03974
03975 if ( id == 2 )
03976 {
03977 mirrorX();
03978 doneMirrorMap = true;
03979 }
03980
03981 if ( id == 3 )
03982 {
03983 mirrorY();
03984 doneMirrorMap = true;
03985 }
03986
03987 }
03988
03989 void MirrorMap::init( void )
03990 {
03991 doneMirrorMap = false;
03992
03993 mirrorUnits = true;
03994 mirrorBuildings = true;
03995 mirrorObjects = true;
03996 mirrorMines = true;
03997 mirrorResources = true;
03998 mirrorWeather = true;
03999 for ( int i=0; i<8; i++ )
04000 playerTranslation[ i ] = 7-i;
04001 playerTranslation[ 8 ] = 8;
04002
04003 tdialogbox::init();
04004 title = "Mirror Map";
04005
04006 xsize = 400;
04007 ysize = 450;
04008
04009 x1 = -1;
04010 y1 = -1;
04011
04012 addbutton( "~C~ancel", 10, ysize - 35, xsize / 3 - 5, ysize - 10, 0, 1, 1, true );
04013 addkey ( 1, ct_esc );
04014
04015 addbutton( "Mirror ~X~", xsize / 3 + 5, ysize - 35, xsize / 3 * 2 - 5, ysize - 10, 0, 1, 2, true );
04016 addkey ( 2, ct_x );
04017
04018 addbutton ( "Mirror ~Y~", xsize / 3 * 2 + 5, ysize - 35, xsize - 10, ysize - 10, 0, 1, 3, true );
04019 addkey ( 3, ct_y );
04020
04021 addbutton( "~O~bjects", xsize - 100, 50, xsize - 10, 65, 3, 0, 4, true );
04022 addeingabe( 4, &mirrorObjects, 0, lightgray );
04023 addkey ( 4, ct_o );
04024
04025 addbutton( "~U~nits", xsize - 100, 70, xsize - 10, 85, 3, 0, 5, true );
04026 addeingabe( 5, &mirrorUnits, 0, lightgray );
04027 addkey ( 5, ct_u );
04028
04029 addbutton( "~B~uildings", xsize - 100, 90, xsize - 10, 105, 3, 0, 6, true );
04030 addeingabe( 6, &mirrorBuildings, 0, lightgray );
04031 addkey ( 6, ct_b );
04032
04033 addbutton( "~M~ines", xsize - 100, 110, xsize - 10, 125, 3, 0, 7, true );
04034 addeingabe( 7, &mirrorMines, 0, lightgray );
04035 addkey ( 7, ct_m );
04036
04037 addbutton( "~R~esources", xsize - 100, 130, xsize - 10, 145, 3, 0, 8, true );
04038 addeingabe( 8, &mirrorResources, 0, lightgray );
04039 addkey ( 8, ct_r );
04040
04041 addbutton( "~W~eather", xsize - 100, 150, xsize - 10, 165, 3, 0, 9, true );
04042 addeingabe( 9, &mirrorWeather, 0, lightgray );
04043 addkey ( 9, ct_w );
04044
04045 addbutton( "Player Conversions:", 30, 50, xsize - 120, 70, 0, 0, 10, true );
04046 addbutton( "Player 0:", 30, 80, 130, 95, 2, 0, 12, true );
04047 addeingabe( 12, &playerTranslation[ 0 ], 0, 8 );
04048 addbutton( "Player 1:", 30, 110, 130, 125, 2, 0, 13, true );
04049 addeingabe( 13, &playerTranslation[ 1 ], 0, 8 );
04050 addbutton( "Player 2:", 30, 140, 130, 155, 2, 0, 14, true );
04051 addeingabe( 14, &playerTranslation[ 2 ], 0, 8 );
04052 addbutton( "Player 3:", 30, 170, 130, 185, 2, 0, 15, true );
04053 addeingabe( 15, &playerTranslation[ 3 ], 0, 8 );
04054 addbutton( "Player 4:", 30, 200, 130, 215, 2, 0, 16, true );
04055 addeingabe( 16, &playerTranslation[ 4 ], 0, 8 );
04056 addbutton( "Player 5:", 150, 80, xsize - 120, 95, 2, 0, 17, true );
04057 addeingabe( 17, &playerTranslation[ 5 ], 0, 8 );
04058 addbutton( "Player 6:", 150, 110, xsize - 120, 125, 2, 0, 18, true );
04059 addeingabe( 18, &playerTranslation[ 6 ], 0, 8 );
04060 addbutton( "Player 7:", 150, 140, xsize - 120, 155, 2, 0, 19, true );
04061 addeingabe( 19, &playerTranslation[ 7 ], 0, 8 );
04062 addbutton( "Player 8:", 150, 170, xsize - 120, 185, 2, 0, 20, true );
04063 addeingabe( 20, &playerTranslation[ 8 ], 0, 8 );
04064
04065 buildgraphics();
04066
04067 activefontsettings.font = schriften.smallarial;
04068 activefontsettings.justify = lefttext;
04069 activefontsettings.length = 0;
04070 activefontsettings.background = 255;
04071
04072 showtext2( "Warnings:", x1 + 25, y1 + 220 );
04073 showtext2( "right&lower border might have to be manually fixed", x1 + 25, y1 + 260 );
04074 showtext2( "mountains, battle isle graphics coasts and similar", x1 + 25, y1 + 280 );
04075 showtext2( "terrain needs manual adaption", x1 + 25, y1 + 300 );
04076 showtext2( "building directions might be weird, resulting in:", x1 + 25, y1 + 330 );
04077 showtext2( "- pipeline net might be broken due to building directions", x1 + 25, y1 + 350 );
04078 showtext2( "- buildings might be missing due to terrain", x1 + 25, y1 + 370 );
04079 showtext2( "- units might be missing due to building locations", x1 + 25, y1 + 390 );
04080
04081 }
04082
04083
04084 void MirrorMap::run ( void )
04085 {
04086 mousevisible ( true );
04087 do {
04088 tdialogbox::run();
04089 } while ( !doneMirrorMap );
04090 }
04091
04092
04093 void MirrorMap::mirrorX()
04094 {
04095 if ( actmap->xsize % 2 == 1 ) actmap->resize ( 0, 0, 0, 1 );
04096 int maxX = actmap->xsize/2;
04097 int xOffset = 2;
04098 int directionTranslation[ 6 ] = { 0, 5, 4, 3, 2, 1 };
04099
04100
04101 for ( int x=0; x<maxX; x++ )
04102 {
04103 for ( int y=0; y<actmap->ysize; y++ )
04104 {
04105 int targetX = actmap->xsize - x - xOffset;
04106 if ( y%2 == 0 ) targetX++;
04107 if ( targetX >= actmap->xsize || targetX == x ) continue;
04108
04109 MapField *targetField = actmap->getField( targetX, y );
04110 MapField *sourceField = actmap->getField( x, y );
04111
04112 copyFieldStep1( sourceField, targetField, true, mirrorResources, mirrorWeather );
04113 }
04114 }
04115
04116
04117 for ( int x=0; x<maxX; x++ )
04118 {
04119 for ( int y=0; y<actmap->ysize; y++ )
04120 {
04121 int targetX = actmap->xsize - x - xOffset;
04122 if ( y%2 == 0 ) targetX++;
04123 if ( targetX >= actmap->xsize || targetX == x ) continue;
04124
04125 MapField *targetField = actmap->getField( targetX, y );
04126 MapField *sourceField = actmap->getField( x, y );
04127
04128 copyFieldStep2( sourceField, targetField, actmap, directionTranslation, playerTranslation, mirrorObjects, mirrorBuildings, mirrorUnits, mirrorMines );
04129 }
04130 }
04131 doneMirrorMap = true;
04132 }
04133
04134 void MirrorMap::mirrorY()
04135 {
04136 int yOffset = 2;
04137 int maxY = actmap->ysize/2;
04138 int directionTranslation[ 6 ] = { 3, 2, 1, 0, 5, 4 };
04139
04140
04141 for ( int x=0; x<actmap->xsize; x++ )
04142 {
04143 for ( int y=0; y<maxY; y++ )
04144 {
04145 int targetY = actmap->ysize - y - yOffset;
04146
04147 MapField *targetField = actmap->getField( x, targetY );
04148 MapField *sourceField = actmap->getField( x, y );
04149
04150 copyFieldStep1( sourceField, targetField, true, mirrorResources, mirrorWeather );
04151 }
04152 }
04153
04154
04155 for ( int x=0; x<actmap->xsize; x++ )
04156 {
04157 for ( int y=0; y<maxY; y++ )
04158 {
04159 int targetY = actmap->ysize - y - yOffset;
04160
04161 MapField *targetField = actmap->getField( x, targetY );
04162 MapField *sourceField = actmap->getField( x, y );
04163
04164 copyFieldStep2( sourceField, targetField, actmap, directionTranslation, playerTranslation, mirrorObjects, mirrorBuildings, mirrorUnits, mirrorMines );
04165 }
04166 }
04167 doneMirrorMap = true;
04168 }
04169
04170 void mirrorMap()
04171 {
04172 MirrorMap mm;
04173 mm.init();
04174 mm.run();
04175 mm.done();
04176 mapChanged( actmap );
04177 displaymap();
04178 }
04179
04180
04181
04182
04183
04184
04185
04186
04187
04188
04189
04190
04191
04192 class CopyMap : public FieldAddressing, public ASC_PG_Dialog
04193 {
04194 private:
04195 GameMap *map;
04196 bool* fieldCopied;
04197
04198 int mapStartX, mapStartY, mapEndX, mapEndY, sizeX, sizeY;
04199 int copyStep;
04200
04201 int *directionTranslation;
04202 int *playerTranslation;
04203
04204 PG_CheckButton* mirrorTerrain;
04205 PG_CheckButton* mirrorResources;
04206 PG_CheckButton* mirrorWeather;
04207 PG_CheckButton* mirrorObjects;
04208 PG_CheckButton* mirrorBuildings;
04209 PG_CheckButton* mirrorUnits;
04210 PG_CheckButton* mirrorMines;
04211
04212 PG_CheckButton* mirrorX;
04213 PG_CheckButton* mirrorY;
04214
04215 PG_CheckButton* autoIncreaseMapSize;
04216
04217 PG_LineEdit* playerTranslation0;
04218 PG_LineEdit* playerTranslation1;
04219 PG_LineEdit* playerTranslation2;
04220 PG_LineEdit* playerTranslation3;
04221 PG_LineEdit* playerTranslation4;
04222 PG_LineEdit* playerTranslation5;
04223 PG_LineEdit* playerTranslation6;
04224 PG_LineEdit* playerTranslation7;
04225 PG_LineEdit* playerTranslation8;
04226
04227
04228 public:
04229 CopyMap();
04230 ~CopyMap();
04231 bool paste();
04232 void copy();
04233 void selectArea();
04234
04235 protected:
04236 virtual void fieldOperator( const MapCoordinate& point );
04237 };
04238
04239 CopyMap::CopyMap() : FieldAddressing( actmap ), ASC_PG_Dialog( NULL, PG_Rect( 30, 30, 550, 400 ), "Paste Options" )
04240 {
04241 addressingMode = poly;
04242 mapStartX = -1;
04243 mapStartY = -1;
04244 mapEndX = -1;
04245 mapEndY = -1;
04246 map = NULL;
04247 fieldCopied = NULL;
04248
04249 directionTranslation = new int[ 6 ];
04250 for ( int i=0; i<6; i++ ) directionTranslation[ i ] = i;
04251 playerTranslation = new int[ 9 ];
04252 for ( int i=0; i<9; i++ ) playerTranslation[ i ] = i;
04253
04254 int dialogLine = 0;
04255 int lineHeight = 20;
04256 int lineSpacing = 10;
04257
04258 int startX = 20;
04259 int startY = 20;
04260 int startX2 = 200;
04261 int startX3 = 250;
04262 int startX4 = 400;
04263 int xSpacer = 20;
04264
04265 PG_Label* label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04266 label->SetAlignment( PG_Label::LEFT );
04267 label->SetText( "Terrain" );
04268 mirrorTerrain = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04269 mirrorTerrain->SetPressed();
04270 dialogLine++;
04271
04272 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04273 label->SetAlignment( PG_Label::LEFT );
04274 label->SetText( "Resources" );
04275 mirrorResources = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04276 mirrorResources->SetPressed();
04277 dialogLine++;
04278
04279 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04280 label->SetAlignment( PG_Label::LEFT );
04281 label->SetText( "Weather" );
04282 mirrorWeather = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04283 mirrorWeather->SetPressed();
04284 dialogLine++;
04285
04286 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04287 label->SetAlignment( PG_Label::LEFT );
04288 label->SetText( "Objects" );
04289 mirrorObjects = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04290 mirrorObjects->SetPressed();
04291 dialogLine++;
04292
04293 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04294 label->SetAlignment( PG_Label::LEFT );
04295 label->SetText( "Buildings" );
04296 mirrorBuildings = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04297 mirrorBuildings->SetPressed();
04298 dialogLine++;
04299
04300 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04301 label->SetAlignment( PG_Label::LEFT );
04302 label->SetText( "Units" );
04303 mirrorUnits = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04304 mirrorUnits->SetPressed();
04305 dialogLine++;
04306
04307 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04308 label->SetAlignment( PG_Label::LEFT );
04309 label->SetText( "Mines" );
04310 mirrorMines = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04311 mirrorMines->SetPressed();
04312 dialogLine++;
04313
04314 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04315 label->SetAlignment( PG_Label::LEFT );
04316 label->SetText( "X" );
04317 mirrorX = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04318 dialogLine++;
04319
04320 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04321 label->SetAlignment( PG_Label::LEFT );
04322 label->SetText( "Y" );
04323 mirrorY = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) ,startX3 - xSpacer - startX2, lineHeight ) );
04324 dialogLine++;
04325
04326 label = new PG_Label ( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ) );
04327 label->SetAlignment( PG_Label::LEFT );
04328 label->SetText( "autoIncreaseMapSize" );
04329 autoIncreaseMapSize = new PG_CheckButton( this, PG_Rect( startX2, startY + dialogLine*(lineHeight+lineSpacing) , startX3 - xSpacer - startX2, lineHeight ) );
04330 autoIncreaseMapSize->SetPressed();
04331 dialogLine++;
04332
04333
04334 PG_Button* ok = new PG_Button( this, PG_Rect( startX, startY + dialogLine*(lineHeight+lineSpacing) , startX2 - xSpacer - startX, lineHeight ), "Paste" );
04335 ok->sigClick.connect( SigC::slot( *this, &CopyMap::paste ));
04336
04337 dialogLine = 0;
04338
04339 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04340 label->SetAlignment( PG_Label::LEFT );
04341 label->SetText( "playerTranslation0" );
04342 playerTranslation0 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04343 playerTranslation0->SetText( "0" );
04344 dialogLine++;
04345
04346 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04347 label->SetAlignment( PG_Label::LEFT );
04348 label->SetText( "playerTranslation1" );
04349 playerTranslation1 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04350 playerTranslation1->SetText( "1" );
04351 dialogLine++;
04352
04353 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04354 label->SetAlignment( PG_Label::LEFT );
04355 label->SetText( "playerTranslation2" );
04356 playerTranslation2 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04357 playerTranslation2->SetText( "2" );
04358 dialogLine++;
04359
04360 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04361 label->SetAlignment( PG_Label::LEFT );
04362 label->SetText( "playerTranslation3" );
04363 playerTranslation3 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04364 playerTranslation3->SetText( "3" );
04365 dialogLine++;
04366
04367 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04368 label->SetAlignment( PG_Label::LEFT );
04369 label->SetText( "playerTranslation4" );
04370 playerTranslation4 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04371 playerTranslation4->SetText( "4" );
04372 dialogLine++;
04373
04374 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04375 label->SetAlignment( PG_Label::LEFT );
04376 label->SetText( "playerTranslation5" );
04377 playerTranslation5 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04378 playerTranslation5->SetText( "5" );
04379 dialogLine++;
04380
04381 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04382 label->SetAlignment( PG_Label::LEFT );
04383 label->SetText( "playerTranslation6" );
04384 playerTranslation6 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04385 playerTranslation6->SetText( "6" );
04386 dialogLine++;
04387
04388 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04389 label->SetAlignment( PG_Label::LEFT );
04390 label->SetText( "playerTranslation7" );
04391 playerTranslation7 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04392 playerTranslation7->SetText( "7" );
04393 dialogLine++;
04394
04395 label = new PG_Label ( this, PG_Rect( startX3, startY + dialogLine*(lineHeight+lineSpacing) , startX4 - xSpacer - startX, lineHeight ) );
04396 label->SetAlignment( PG_Label::LEFT );
04397 label->SetText( "playerTranslation8" );
04398 playerTranslation8 = new PG_LineEdit( this, PG_Rect( startX4, startY + dialogLine*(lineHeight+lineSpacing) , this->Width() - xSpacer - startX4, lineHeight ) );
04399 playerTranslation8->SetText( "8" );
04400 dialogLine++;
04401
04402 }
04403
04404 CopyMap::~CopyMap()
04405 {
04406 if ( map != NULL )
04407 {
04408 delete map;
04409 delete[] fieldCopied;
04410 }
04411 delete[] directionTranslation;
04412 delete[] playerTranslation;
04413 }
04414
04415 void CopyMap::selectArea()
04416 {
04417 polygons.clear();
04418
04419 Poly_gon area;
04420 editpolygon( area );
04421 setPolygon( area );
04422 }
04423
04424 void CopyMap::copy()
04425 {
04426 if ( map != NULL )
04427 {
04428 delete map;
04429 delete[] fieldCopied;
04430 }
04431
04432 mapStartX = -1;
04433 mapStartY = -1;
04434 mapEndX = -1;
04435 mapEndY = -1;
04436 copyStep = 0;
04437 operate();
04438
04439 sizeX = mapEndX-mapStartX + 1;
04440 sizeY = mapEndY-mapStartY + 1;
04441
04442 map = new GameMap;
04443 map->allocateFields( sizeX, sizeY, terrainTypeRepository.getObject_byID(30)->weather[0] );
04444
04445 int* oldDirectoyTranslation = directionTranslation;
04446 int* oldPlayerTranslation = playerTranslation;
04447
04448 directionTranslation = new int[ 6 ];
04449 for ( int i=0; i<6; i++ ) directionTranslation[ i ] = i;
04450 playerTranslation = new int[ 9 ];
04451 for ( int i=0; i<9; i++ ) playerTranslation[ i ] = i;
04452
04453 fieldCopied = new bool[ sizeY * sizeX ];
04454 for ( int i=0; i<sizeY * sizeX; i++ )
04455 fieldCopied[ i ] = false;
04456
04457 copyStep = 1;
04458 operate();
04459 copyStep = 2;
04460 operate();
04461
04462 delete[] directionTranslation;
04463 delete[] playerTranslation;
04464 directionTranslation = oldDirectoyTranslation;
04465 playerTranslation = oldPlayerTranslation;
04466 }
04467
04468 bool CopyMap::paste()
04469 {
04470 QuitModal();
04471 Hide();
04472 if ( map == NULL ) return false;
04473
04474 MapField *field = getactfield();
04475 if ( field == NULL ) return false;
04476
04477 int pasteStartX = field->getx();
04478 int pasteStartY = field->gety();
04479
04480 if ( autoIncreaseMapSize->GetPressed() )
04481 {
04482 int targetSizeX = pasteStartX + map->xsize;
04483 int targetSizeY = pasteStartY + map->ysize;
04484
04485 if ( targetSizeY%2 == 1 )
04486 targetSizeY++;
04487
04488 if ( targetSizeX > actmap->xsize )
04489 {
04490 actmap->resize( 0, 0, 0, targetSizeX - actmap->xsize );
04491 }
04492
04493 if ( targetSizeY > actmap->ysize )
04494 {
04495 actmap->resize( 0, targetSizeY - actmap->ysize, 0, 0 );
04496 }
04497 }
04498
04499 playerTranslation[ 0 ] = atoi( playerTranslation0->GetText() );
04500 playerTranslation[ 1 ] = atoi( playerTranslation1->GetText() );
04501 playerTranslation[ 2 ] = atoi( playerTranslation2->GetText() );
04502 playerTranslation[ 3 ] = atoi( playerTranslation3->GetText() );
04503 playerTranslation[ 4 ] = atoi( playerTranslation4->GetText() );
04504 playerTranslation[ 5 ] = atoi( playerTranslation5->GetText() );
04505 playerTranslation[ 6 ] = atoi( playerTranslation6->GetText() );
04506 playerTranslation[ 7 ] = atoi( playerTranslation7->GetText() );
04507 playerTranslation[ 8 ] = atoi( playerTranslation8->GetText() );
04508
04509 int* oldDirectoyTranslation = directionTranslation;
04510
04511 directionTranslation = new int[ 6 ];
04512 for ( int i=0; i<6; i++ ) directionTranslation[ i ] = i;
04513
04514 if ( mirrorY->GetPressed() )
04515 {
04516 int directionTranslationNew[ 6 ] =
04517 {
04518 directionTranslation[ 3 ],
04519 directionTranslation[ 2 ],
04520 directionTranslation[ 1 ],
04521 directionTranslation[ 0 ],
04522 directionTranslation[ 5 ],
04523 directionTranslation[ 4 ]
04524 };
04525
04526 for ( int i=0; i<6; i++ ) directionTranslation[ i ] = directionTranslationNew[ i ];
04527 }
04528
04529 if ( mirrorX->GetPressed() )
04530 {
04531 int directionTranslationNew[ 6 ] =
04532 {
04533 directionTranslation[ 0 ],
04534 directionTranslation[ 5 ],
04535 directionTranslation[ 4 ],
04536 directionTranslation[ 3 ],
04537 directionTranslation[ 2 ],
04538 directionTranslation[ 1 ]
04539 };
04540
04541 for ( int i=0; i<6; i++ ) directionTranslation[ i ] = directionTranslationNew[ i ];
04542 }
04543
04544
04545
04546
04547 for ( int x=0; x<map->xsize; x++ )
04548 {
04549 for ( int y=0; y<map->ysize; y++ )
04550 {
04551 if ( fieldCopied[ x + y * sizeX ] )
04552 {
04553 int fieldX = pasteStartX + x;
04554 int fieldY = pasteStartY + y;
04555
04556 if ( pasteStartY%2 == 1 && fieldY%2 == 0 )
04557 fieldX++;
04558
04559 if ( mirrorX->GetPressed() )
04560 {
04561 fieldX = pasteStartX + sizeX - x - 1;
04562
04563 if ( pasteStartY%2 == 0 && fieldY%2 == 1 )
04564 fieldX--;
04565 }
04566
04567 if ( mirrorY->GetPressed() )
04568 {
04569 fieldY = pasteStartY + sizeY - y - 1;
04570 }
04571
04572 if ( fieldX >= actmap->xsize ) continue;
04573 if ( fieldY >= actmap->ysize ) continue;
04574
04575 MapField* target = actmap->getField( fieldX, fieldY );
04576 MapField* source = map->getField( x, y );
04577
04578 copyFieldStep1( source, target, mirrorTerrain->GetPressed(), mirrorResources->GetPressed(), mirrorWeather->GetPressed() );
04579 }
04580 }
04581 }
04582
04583 for ( int x=0; x<map->xsize; x++ )
04584 {
04585 for ( int y=0; y<map->ysize; y++ )
04586 {
04587 if ( fieldCopied[ x + y * sizeX ] )
04588 {
04589 int fieldX = pasteStartX + x;
04590 int fieldY = pasteStartY + y;
04591
04592 if ( pasteStartY%2 == 1 && fieldY%2 == 0 )
04593 fieldX++;
04594
04595 if ( mirrorX->GetPressed() )
04596 {
04597 fieldX = pasteStartX + sizeX - x - 1;
04598
04599 if ( pasteStartY%2 == 0 && fieldY%2 == 1 )
04600 fieldX--;
04601 }
04602
04603 if ( mirrorY->GetPressed() )
04604 {
04605 fieldY = pasteStartY + sizeY - y - 1;
04606 }
04607
04608 if ( fieldX >= actmap->xsize ) continue;
04609 if ( fieldY >= actmap->ysize ) continue;
04610
04611 MapField* target = actmap->getField( fieldX, fieldY );
04612 MapField* source = map->getField( x, y );
04613
04614 copyFieldStep2( source, target, actmap, directionTranslation, playerTranslation, mirrorObjects->GetPressed(), mirrorBuildings->GetPressed(), mirrorUnits->GetPressed(), mirrorMines->GetPressed() );
04615 }
04616 }
04617 }
04618
04619 delete[] directionTranslation;
04620 directionTranslation = oldDirectoyTranslation;
04621
04622 return true;
04623
04624 }
04625
04626 void CopyMap::fieldOperator( const MapCoordinate& point )
04627 {
04628 int mapX = point.x - mapStartX;
04629 int mapY = point.y - mapStartY;
04630
04631 if ( mapStartY%2 == 1 && mapY%2 == 1 )
04632 mapX--;
04633
04634 if ( copyStep == 0 )
04635 {
04636 if ( mapStartX == -1 || point.x < mapStartX )
04637 mapStartX = point.x;
04638
04639 if ( mapStartY == -1 || point.y < mapStartY )
04640 mapStartY = point.y;
04641
04642 if ( mapEndX == -1 || point.x > mapEndX )
04643 mapEndX = point.x;
04644
04645 if ( mapEndY == -1 || point.y > mapEndY )
04646 mapEndY = point.y;
04647 } else if ( copyStep == 1 )
04648 {
04649 fieldCopied[ mapX + mapY * sizeX ] = true;
04650
04651 MapField* source = actmap->getField( point );
04652 MapField* target = map->getField( mapX, mapY );
04653
04654
04655
04656 copyFieldStep1( source, target, true, true, true );
04657
04658 } else if ( copyStep == 2 )
04659 {
04660 MapField* source = actmap->getField( point );
04661 MapField* target = map->getField( mapX, mapY );
04662
04663 copyFieldStep2( source, target, map, directionTranslation, playerTranslation, true, true, true, true );
04664
04665 }
04666 }
04667
04668 CopyMap *copyMap = NULL;
04669
04670 void copyArea()
04671 {
04672 if ( copyMap == NULL )
04673 {
04674 copyMap = new CopyMap();
04675 }
04676 copyMap -> selectArea();
04677 copyMap -> copy();
04678 }
04679
04680 void pasteArea()
04681 {
04682 if ( copyMap != NULL )
04683 {
04684 copyMap -> Show();
04685 copyMap -> RunModal();
04686 mapChanged( actmap );
04687 displaymap();
04688 }
04689 }
04690
04691 void selectAndRunLuaScript( const ASCString& filenamewildcard )
04692 {
04693 ASCString file = selectFile( filenamewildcard, true );
04694 if ( file.size() ) {
04695 LuaState state;
04696 LuaRunner runner( state );
04697 runner.runFile( file );
04698 if ( !runner.getErrors().empty() )
04699 errorMessage( runner.getErrors() );
04700 updateFieldInfo();
04701 }
04702 }
04703
04704
04705
04706
04707
04708
04709
04710
04711
04712
04713
04714 void testDebugFunction()
04715 {
04716
04717 actmap->cleartemps(7);
04718 for ( int x = 0; x < actmap->xsize; ++x )
04719 for ( int y = 0; y < actmap->ysize; ++y ) {
04720 MapField* fld = actmap->getField(x,y);
04721 if ( fld->getVisibility(5) >= visible_now )
04722 fld->a.temp = 1;
04723 else
04724 fld->a.temp = 0;
04725 }
04726
04727 repaintMap();
04728 }