00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdio.h>
00025 #include <cstring>
00026 #include <ctype.h>
00027 #include <stdlib.h>
00028 #include <math.h>
00029
00030 #if TIME_WITH_SYS_TIME
00031 # include <sys/time.h>
00032 # include <time.h>
00033 #else
00034 # if HAVE_SYS_TIME_H
00035 # include <sys/time.h>
00036 # else
00037 # include <time.h>
00038 # endif
00039 #endif
00040
00041
00042 #include "vehicletype.h"
00043 #include "buildingtype.h"
00044
00045 #include "basegfx.h"
00046 #include "gamedlg.h"
00047 #include "stack.h"
00048 #include "controls.h"
00049 #include "gameoptions.h"
00050 #include "errors.h"
00051 #include "viewcalculation.h"
00052 #include "replay.h"
00053 #include "itemrepository.h"
00054 #include "strtmesg.h"
00055 #include "dialogs/editmapparam.h"
00056 #include "dlg_box.h"
00057 #include "spfst.h"
00058 #include "dialog.h"
00059
00060 #include "widgets/textrenderer.h"
00061
00062 class tchoosetechnology : public tdialogbox {
00063 typedef vector<const Technology*> Techs;
00064 Techs techs;
00065 bool endDialog;
00066
00067 char markedbackgrnd;
00068 int technum;
00069 int dispnum;
00070 int firstshowntech;
00071 int markedtech;
00072 void disp ( void );
00073 void buttonpressed ( int id );
00074 int gx ( void );
00075 int gy ( int i );
00076 void check( void );
00077 public:
00078 void init ( void );
00079 virtual void run ( void );
00080 };
00081
00082 void tchoosetechnology::init(void)
00083 {
00084 endDialog = false;
00085 tdialogbox::init();
00086 title = "research";
00087
00088 firstshowntech = 0;
00089 dispnum = 10;
00090 markedtech = 0;
00091
00092 check();
00093 if ( technum > dispnum )
00094 addscrollbar ( xsize - 40, 70, xsize - 20, ysize - 40, &technum, dispnum, &firstshowntech, 1, 0 );
00095
00096 addbutton ( "~O~k", 10, ysize - 30, xsize - 10, ysize - 10 , 0, 1, 10, true );
00097 addkey ( 10, ct_enter );
00098 addkey ( 10, ct_space );
00099
00100
00101
00102
00103
00104 }
00105
00106 bool technologyComp ( const Technology* t1, const Technology* t2 )
00107 {
00108 return t1->techlevel < t2->techlevel;
00109 }
00110
00111 void tchoosetechnology::check(void)
00112 {
00113 technum = 0;
00114 Research* resrch = &actmap->player[actmap->actplayer].research;
00115
00116 for (int i = 0; i < technologyRepository.getNum(); i++) {
00117 const Technology* tech = technologyRepository.getObject_byPos( i );
00118 if ( tech ) {
00119 ResearchAvailabilityStatus a = resrch->techAvailable ( tech );
00120 if ( a == Available ) {
00121 techs.push_back ( tech );
00122 technum++;
00123 }
00124 }
00125 }
00126 sort ( techs.begin(), techs.end(), technologyComp );
00127 }
00128
00129
00130 int tchoosetechnology::gx ( void )
00131 {
00132 return x1 + 20;
00133 }
00134
00135 int tchoosetechnology::gy ( int i )
00136 {
00137 return y1 + starty + 40 + ( i - firstshowntech ) * 25;
00138 }
00139
00140 void tchoosetechnology::disp(void)
00141 {
00142 activefontsettings.font = schriften.smallarial;
00143 activefontsettings.justify = lefttext;
00144 activefontsettings.length = 300;
00145 for ( int i = firstshowntech; i < technum && i < firstshowntech + dispnum; i++ ) {
00146 if ( i == markedtech )
00147 activefontsettings.background = 25;
00148 else
00149 activefontsettings.background = dblue;
00150
00151 int x = gx();
00152 int y = gy(i);
00153
00154 activefontsettings.length = 250;
00155 showtext2(techs[i]->name, x,y ) ;
00156
00157 activefontsettings.length = 60;
00158 showtext2( strrr( techs[i]->researchpoints), x + 260,y ) ;
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 activefontsettings.length = 40;
00172 if ( techs[i]->relatedUnitID > 0 && actmap->getvehicletype_byid( techs[i]->relatedUnitID )) {
00173
00174 showtext2("(O)", x1 + xsize - 90,y ) ;
00175 } else
00176 showtext2(" ", x1 + xsize - 90,y ) ;
00177
00178 }
00179 }
00180
00181 void tchoosetechnology::buttonpressed ( int id )
00182 {
00183 if ( id == 1 )
00184 disp();
00185 if ( id == 10 )
00186 endDialog = true;
00187 }
00188
00189
00190 void tchoosetechnology::run(void)
00191 {
00192
00193 if ( !technum && !actmap->player[actmap->actplayer].research.techsAvail )
00194 return;
00195
00196 actmap->player[actmap->actplayer].research.techsAvail = true;
00197
00198 buildgraphics();
00199 markedbackgrnd = lightblue;
00200 disp();
00201
00202 npush ( activefontsettings.color );
00203 activefontsettings.background = black;
00204 activefontsettings.color = white;
00205 activefontsettings.font = schriften.smallarial;
00206 activefontsettings.justify = lefttext;
00207 activefontsettings.length = xsize + x1 - gx() - 30;
00208 showtext2( "Technology", gx(), y1+starty+10 ) ;
00209
00210 activefontsettings.background = 255;
00211 showtext2( "Points", gx()+260, y1+starty+10 ) ;
00212
00213
00214 showtext2( "UnitInfo", x1 + xsize - 110, y1+starty+10 ) ;
00215
00216 npop ( activefontsettings.color );
00217
00218 mousevisible(true);
00219 if (technum == 0) {
00220 showtext2("no further technologies to develop !", x1 + 20, y1 + starty + 30);
00221 actmap->player[actmap->actplayer].research.activetechnology = NULL;
00222 do {
00223 tdialogbox::run();
00224 } while (!endDialog);
00225 actmap->player[actmap->actplayer].research.techsAvail = false;
00226 }
00227 else {
00228 do {
00229 tdialogbox::run();
00230 int oldmark = markedtech;
00231 if ( mouseparams.taste == 1 ) {
00232 for ( int i = firstshowntech; i < technum && i < firstshowntech + dispnum; i++ ) {
00233 int x = gx();
00234 int y = gy(i);
00235 if ( mouseinrect ( x1 + xsize - 90, y, x1 + xsize - 50, y + 20 ) ) {
00236 if ( techs[i]->relatedUnitID > 0 ) {
00237 Vehicletype* vt = actmap->getvehicletype_byid( techs[i]->relatedUnitID );
00238 if ( vt ) {
00239 while ( mouseparams.taste == 1 )
00240 releasetimeslice();
00241
00242
00243 }
00244 }
00245 }
00246
00247 if ( mouseinrect ( x, y, x1 + xsize - 100, y + 20 ) ){
00248 if ( markedtech == i )
00249 endDialog = true;
00250 else
00251 markedtech = i;
00252
00253 if (markedtech != oldmark) {
00254 disp();
00255 oldmark = markedtech;
00256 }
00257
00258 while ( mouseparams.taste )
00259 releasetimeslice();
00260 }
00261 }
00262 }
00263
00264 switch (taste) {
00265
00266 case ct_down: if ( markedtech+1 < technum )
00267 markedtech++;
00268 break;
00269
00270 case ct_up: if ( markedtech )
00271 markedtech--;
00272 break;
00273 }
00274 if (markedtech != oldmark) {
00275 if ( markedtech < firstshowntech ) {
00276 firstshowntech = markedtech;
00277 enablebutton ( 1 );
00278 }
00279 if ( markedtech >= firstshowntech + dispnum ) {
00280 firstshowntech = markedtech - dispnum + 1;
00281 enablebutton ( 1 );
00282 }
00283 disp();
00284 }
00285
00286 } while ( !endDialog );
00287
00288
00289
00290
00291
00292
00293
00294 actmap->player[actmap->actplayer].research.activetechnology = techs[markedtech];
00295
00296 }
00297 }
00298
00299
00300 void choosetechnology(void)
00301 {
00302 tchoosetechnology ct;
00303
00304 ct.init();
00305 ct.run();
00306 ct.done();
00307 }
00308
00309
00310
00311
00312
00313
00314 class ttributepayments : public tdialogbox {
00315 GameMap::ResourceTribute trib;
00316 int oldplayer;
00317 int player;
00318 void paintactplayer ( void );
00319 void paintvalues ( void );
00320 int status;
00321 int players[8];
00322 int wind1y, wind2y ;
00323 int wind1x, wind2x ;
00324
00325 public:
00326 void init ( void );
00327 void buttonpressed ( int id );
00328 void run ( void );
00329 };
00330
00331
00332 void ttributepayments :: init ( void )
00333 {
00334 int i;
00335
00336 tdialogbox::init();
00337 oldplayer = -1;
00338 player = 0;
00339 status = 0;
00340 xsize = 550;
00341 ysize = 400;
00342 title = "transfer resources";
00343
00344 trib = actmap->tribute;
00345
00346 memset ( &players, -1, sizeof( players ));
00347
00348 windowstyle &= ~dlg_in3d;
00349
00350 addbutton ( "~O~k", 10, ysize - 40, xsize/2 - 5, ysize - 10, 0, 1, 1, true );
00351 addkey ( 1, ct_enter );
00352
00353 addbutton ( "~C~ancel", xsize/2 + 5, ysize - 40, xsize-10 - 5, ysize - 10, 0, 1, 2, true );
00354 addkey ( 2, ct_esc );
00355
00356 wind1y = starty + 10;
00357
00358
00359
00360 buildgraphics();
00361
00362 for (i = 0; i < 3; i++)
00363 addbutton ( NULL, 250, wind1y + 15 + i * 40, 350, wind1y + 32 + i * 40, 2, 1, 3 + i, true );
00364
00365 int pos = 0;
00366 for ( i = 0; i < 8; i++ )
00367 if ( actmap->player[i].exist() )
00368 if ( i != actmap->actplayer )
00369 players[pos++] = i;
00370
00371
00372 activefontsettings.font = schriften.smallarial;
00373 activefontsettings.color = black;
00374 activefontsettings.length = 145 - 55;
00375 activefontsettings.justify = lefttext;
00376 activefontsettings.height = 0;
00377
00378 for ( i = 0; i < pos; i++) {
00379 bar ( x1 + 30, y1 + starty + 30 + i * 30, x1 + 50, y1 + starty + 50 + i * 30, 20 + players[i] * 8 );
00380 showtext2 ( actmap->player[players[i]].getName().c_str(), x1 + 55, y1 + starty + 30 + i * 30 );
00381 }
00382
00383 wind2y = starty + ( ysize - starty - 60 ) /2 + 5;
00384
00385 wind1x = 255 ;
00386 wind2x = 375 ;
00387
00388 rahmen ( true, x1 + 10, y1 + starty, x1 + xsize - 10, y1 + ysize - 50 );
00389 rahmen3 ( "player", x1 + 20, y1 + starty + 10, x1 + 150, y1 + ysize - 60, 1 );
00390
00391 rahmen3 ( "you send", x1 + 160, y1 + wind1y, x1 + wind2x - 10, y1 + wind2y - 10, 1 );
00392 rahmen3 ( "you still have outstanding", x1 + 160, y1 + wind2y, x1 + wind2x - 10, y1 + ysize - 60 , 1 );
00393
00394 rahmen3 ( "you have sent", x1 + wind2x - 5, y1 + wind1y, x1 + xsize - 20, y1 + wind2y - 10, 1 );
00395 rahmen3 ( "you got", x1 + wind2x - 5, y1 + wind2y, x1 + xsize - 20, y1 + ysize - 60 , 1 );
00396
00397
00398 activefontsettings.font = schriften.smallarial;
00399 activefontsettings.color = textcolor;
00400 activefontsettings.length = 0;
00401 activefontsettings.justify = lefttext;
00402 activefontsettings.height = 0;
00403
00404 for ( i = 0; i < 3; i++) {
00405 showtext2 ( resourceNames[i], x1 + 170, y1 + wind1y + 15 + i * 40 );
00406 showtext2 ( resourceNames[i], x1 + 170, y1 + wind2y + 15 + i * 40 );
00407
00408 rectangle ( x1 + wind2x, y1 + wind1y + 15 + i * 40, x1 + xsize - 30 , y1 + wind1y + 32 + i * 40, black );
00409 rectangle ( x1 + wind1x, y1 + wind2y + 15 + i * 40, x1 + wind2x - 15, y1 + wind2y + 32 + i * 40, black );
00410 rectangle ( x1 + wind2x, y1 + wind2y + 15 + i * 40, x1 + xsize - 30 , y1 + wind2y + 32 + i * 40, black );
00411 }
00412
00413 paintactplayer();
00414 paintvalues();
00415 }
00416
00417 void ttributepayments :: paintactplayer ( void )
00418 {
00419 int xx1 = x1 + 25;
00420 int xx2 = x1 + 145;
00421 int yy1 = y1 + starty + 25 + oldplayer * 30;
00422 int yy2 = yy1 + 30;
00423 if ( oldplayer != -1 )
00424 xorrectangle ( xx1, yy1, xx2, yy2, 14 );
00425
00426 yy1 = y1 + starty + 25 + player * 30;
00427 yy2 = yy1 + 30;
00428 if ( player != -1 )
00429 xorrectangle ( xx1, yy1, xx2, yy2, 14 );
00430
00431 oldplayer = player;
00432 }
00433
00434 void ttributepayments :: paintvalues ( void )
00435 {
00436 activefontsettings.font = schriften.smallarial;
00437 activefontsettings.color = textcolor;
00438 activefontsettings.justify = lefttext;
00439 activefontsettings.height = 0;
00440 activefontsettings.background = dblue;
00441
00442 for ( int i = 0; i < 3; i++) {
00443 addeingabe ( 3+i, &trib.avail[actmap->actplayer][players[player]].resource(i), 0, maxint );
00444 enablebutton ( 3+i );
00445
00446 activefontsettings.length = xsize - 40 - wind2x;
00447 showtext2 ( strrr ( trib.paid[actmap->actplayer][players[player]].resource(i)), x1 + wind2x + 5, y1 + wind2y + 16 + i * 40 );
00448 showtext2 ( strrr ( trib.paid[players[player]][actmap->actplayer].resource(i)), x1 + wind2x + 5, y1 + wind1y + 16 + i * 40 );
00449
00450 activefontsettings.length = wind2x - wind1x - 35;
00451 showtext2 ( strrr ( trib.avail[players[player]][actmap->actplayer].resource(i)), x1 + wind1x + 5, y1 + wind2y + 16 + i * 40 );
00452 }
00453 }
00454
00455
00456 void ttributepayments :: buttonpressed( int id )
00457 {
00458 tdialogbox::buttonpressed( id );
00459 if ( id == 1 )
00460 status = 11;
00461 if ( id == 2 )
00462 status = 10;
00463 }
00464
00465 void ttributepayments :: run ( void )
00466 {
00467 mousevisible(true);
00468 do {
00469 tdialogbox::run();
00470 if ( taste == ct_down ) {
00471 player++;
00472 if ( players[ player ] == -1 )
00473 player = 0;
00474 }
00475 if ( taste == ct_up ) {
00476 player--;
00477 if ( player < 0 )
00478 player = 7;
00479 while ( players[ player] == -1 )
00480 player--;
00481 }
00482 if ( mouseparams.taste & 1 )
00483 for (int i = 0; i < 8; i++) {
00484 if ( (mouseparams.x >= x1 + 25) &&
00485 (mouseparams.y >= y1 + starty + 25 + i * 30) &&
00486 (mouseparams.x <= x1 + 145) &&
00487 (mouseparams.y <= y1 + starty + 55 + i * 30 ) )
00488 if ( players[i] != -1 )
00489 player = i;
00490
00491 }
00492
00493 if ( player != oldplayer ) {
00494 paintactplayer();
00495 paintvalues();
00496 }
00497
00498 } while ( status < 10 );
00499
00500 if ( status >= 11 )
00501 actmap->tribute = trib;
00502 }
00503
00504
00505 void settributepayments ( void )
00506 {
00507 ttributepayments tpm;
00508 tpm.init();
00509 tpm.run();
00510 tpm.done();
00511 }
00512
00513
00514 class tresearchinfo: public tdialogbox {
00515 protected:
00516 int rppt;
00517 int status;
00518
00519
00520
00521 public:
00522 tresearchinfo ( void );
00523 void init ( void );
00524 void buttonpressed ( int id );
00525 void run ( void );
00526
00527 };
00528
00529 tresearchinfo::tresearchinfo ( void )
00530 {
00531 rppt = 0;
00532 status = 0;
00533 }
00534
00535 void tresearchinfo::init ( void )
00536 {
00537 tdialogbox::init();
00538 x1 = -1;
00539 y1 = -1;
00540 xsize = 500;
00541 ysize = 400;
00542 title = "research";
00543 addbutton ( "~O~K", 10, ysize - 30, xsize - 10, ysize - 10, 0, 1, 1, true );
00544 addkey( 1, ct_enter );
00545 addkey( 1, ct_esc );
00546 buildgraphics();
00547 rppt = actmap->player[actmap->actplayer].research.getResearchPerTurn();
00548 rahmen ( true, x1 + 19, y1 + 69, x1 + xsize - 19, y1 + 91 );
00549 bar ( x1 + 20, y1 + 70, x1 + xsize - 20, y1 + 90, dblue );
00550
00551 activefontsettings.font = schriften.smallarial;
00552 activefontsettings.color = textcolor;
00553 activefontsettings.justify = righttext;
00554 activefontsettings.length = 200;
00555 activefontsettings.background = 255;
00556
00557 int textxpos = x1 + xsize / 2 - 5 - activefontsettings.length;
00558
00559 showtext2 ( "name:", textxpos, y1 + 110 );
00560 showtext2 ( "research points:", textxpos, y1 + 140 );
00561 showtext2 ( "research points done:", textxpos, y1 + 170 );
00562 showtext2 ( "research points still needed:", textxpos, y1 + 200 );
00563 showtext2 ( "research done ( % ):", textxpos, y1 + 230 );
00564 showtext2 ( "research points / turn:", textxpos, y1 + 260 );
00565 showtext2 ( "time left (turns):", textxpos, y1 + 290 );
00566
00567
00568 activefontsettings.justify = lefttext;
00569 activefontsettings.length = 0;
00570 textxpos = x1 + xsize / 2 + 5 ;
00571 if ( actmap->player[actmap->actplayer].research.activetechnology ) {
00572 bar ( x1 + 20, y1 + 70, x1 + 20 + (xsize - 40) * actmap->player[actmap->actplayer].research.progress / actmap->player[actmap->actplayer].research.activetechnology->researchpoints, y1 + 90, textcolor );
00573
00574
00575 int rp = actmap->player[actmap->actplayer].research.activetechnology->researchpoints;
00576 int prog = actmap->player[actmap->actplayer].research.progress;
00577 showtext2 ( actmap->player[actmap->actplayer].research.activetechnology->name, textxpos, y1 + 110 );
00578 showtext2 ( strrr ( rp ), textxpos, y1 + 140 );
00579 showtext2 ( strrr ( prog ), textxpos, y1 + 170 );
00580 showtext2 ( strrr ( rp - prog ), textxpos, y1 + 200 );
00581 if ( rp )
00582 showtext2 ( strrr ( 100 * prog / rp ), textxpos, y1 + 230 );
00583 if ( rppt )
00584 showtext2 ( strrr ( actmap->player[actmap->actplayer].research.currentTechAvailableIn() ), textxpos, y1 + 290 );
00585
00586 }
00587 showtext2 ( strrr ( rppt ), textxpos, y1 + 260 );
00588
00589
00590 }
00591
00592 void tresearchinfo::buttonpressed ( int id )
00593 {
00594 if ( id == 1 )
00595 status = 10;
00596 }
00597
00598 void tresearchinfo::run ( void )
00599 {
00600 mousevisible(true);
00601 do {
00602 tdialogbox::run();
00603 } while ( status < 10 );
00604 }
00605
00606
00607 void researchinfo ( void )
00608 { {
00609 tresearchinfo ri;
00610 ri.init();
00611 ri.run();
00612 ri.done();
00613 }
00614 {
00615 vector<ASCString> sv;
00616 for ( vector<int>::iterator i = actmap->player[actmap->actplayer].research.developedTechnologies.begin(); i != actmap->player[actmap->actplayer].research.developedTechnologies.end(); ++i ) {
00617 Technology* t = technologyRepository.getObject_byID( *i );
00618 if ( t )
00619 sv.push_back ( t->name );
00620 }
00621 sort ( sv.begin(), sv.end() );
00622
00623 ASCString s;
00624 for ( vector<ASCString>::iterator i = sv.begin(); i != sv.end(); ++i )
00625 s += *i + "\n";
00626
00627
00628 ViewFormattedText vft ( "Developed Technologies", s, PG_Rect( -1, -1, 500, 500 ));
00629 vft.Show();
00630 vft.RunModal();
00631
00632 }
00633 if ( skeypress( ct_lshift)) {
00634 ASCString s = actmap->player[actmap->actplayer].research.listTriggeredTechAdapter();
00635
00636 ViewFormattedText vft ( "Triggered TechAdapter", s, PG_Rect( -1, -1, 500, 500 ));
00637 vft.Show();
00638 vft.RunModal();
00639 }
00640
00641 }
00642
00643
00644
00645
00646
00647 class tchoosetechlevel : public tdialogbox {
00648 protected:
00649 int techlevel;
00650 int ok;
00651 public:
00652 void init ( void );
00653 void buttonpressed ( int id );
00654 void run ( void );
00655 };
00656
00657 void tchoosetechlevel :: init ( void )
00658 {
00659 tdialogbox :: init ( );
00660 title = "choose techlevel";
00661 xsize = 200;
00662 ysize = 150;
00663 techlevel = 0;
00664 ok = 0;
00665
00666 addbutton ( "~O~k", 10, ysize - 30, xsize - 10, ysize - 10 , 0, 1, 1, true );
00667 addkey ( 1, ct_enter );
00668
00669 addbutton ( "", 10, 60, xsize - 10, 85 , 2, 1, 2, true );
00670 addeingabe ( 2, &techlevel, 0, 255 );
00671 addkey ( 1, ct_space );
00672
00673 buildgraphics();
00674 }
00675
00676 void tchoosetechlevel :: buttonpressed ( int id )
00677 {
00678 tdialogbox:: buttonpressed ( id );
00679 if ( id == 1 )
00680 ok = 1;
00681 }
00682
00683 void tchoosetechlevel :: run ( void )
00684 {
00685 mousevisible ( true );
00686 do {
00687 tdialogbox::run();
00688 } while ( !ok );
00689 if ( techlevel > 0 )
00690 for ( int i = 0; i < 8; i++ )
00691 actmap->player[i].research.settechlevel ( techlevel );
00692
00693 };
00694
00695 void choosetechlevel ( void )
00696 {
00697 tchoosetechlevel ctl;
00698 ctl.init();
00699 ctl.run();
00700 ctl.done();
00701 }
00702
00703
00704
00705 #undef linelength
00706
00707
00708
00709 ASCString writeGameParametersToString ( GameMap* actmap )
00710 {
00711 ASCString s = "The game has been set up with the following game parameters:\n";
00712 s += "(black line: parameter has default value)\n\n";
00713 for ( int i = 0; i< gameparameternum; i++ ) {
00714
00715 int d = actmap->getgameparameter(GameParameter(i)) != gameParameterSettings[i].defaultValue;
00716
00717 if ( d )
00718 s+= "#color4#";
00719
00720 s += gameParameterSettings[i].longName;
00721 s += " = ";
00722 s += strrr ( actmap->getgameparameter(GameParameter(i)) );
00723
00724 if ( d )
00725 s+= "#color0#";
00726 s += "\n";
00727 }
00728 return s;
00729 }
00730
00731 void sendGameParameterAsMail ( GameMap* actmap )
00732 {
00733 ASCString s = writeGameParametersToString ( actmap );
00734
00735 if ( actmap->getgameparameter( cgp_superVisorCanSaveMap) ) {
00736 s = "#color4#Warning ! This game has been started with the option enabled that allows the Supervisor to save the map. This will allow him to spy on everything. \n"
00737 "If you did not initiate this game yourself, don't play with this option unless you were specifically informed why this option had to be enabled. \n"
00738 "#color0# \n" + s;
00739 }
00740
00741 new Message ( s, actmap, 255 );
00742 }
00743
00744
00745 void showGameParameters ( void )
00746 {
00747 ViewFormattedText vft( "Game Parameters", writeGameParametersToString(actmap), PG_Rect( -1, -1, 500, 550 ) );
00748 vft.Show();
00749 vft.RunModal();
00750 }
00751
00752
00753 #if 0
00754
00755 class tmultiplayersettings : public tdialogbox {
00756 protected:
00758 char svpwd_enc[1000];
00759
00761 char svpwd_plt[1000];
00762
00763 int techlevel;
00764 int replays;
00765 int status;
00766 int defaultSettings;
00767 int supervisor;
00768
00769 void setcoordinates ( void );
00770
00771 public:
00772 void init ( void );
00773 void run ( void );
00774 void buttonpressed ( int id );
00775
00776 ~tmultiplayersettings ( );
00777 };
00778
00779
00780
00781 void tmultiplayersettings :: buttonpressed ( int id )
00782 {
00783 tdialogbox :: buttonpressed ( id );
00784 if ( id == 125 )
00785 setmapparameters( actmap );
00786
00787 if ( id == 1 ) {
00788 status = 2;
00789
00790 if ( techlevel )
00791 for ( int i = 0; i < 8; i++ )
00792 actmap->player[i].research.settechlevel ( techlevel );
00793
00794 if ( replays )
00795 actmap->replayinfo = new GameMap::ReplayInfo;
00796 else
00797 if ( actmap->replayinfo ) {
00798 delete actmap->replayinfo;
00799 actmap->replayinfo = NULL;
00800 }
00801
00802 if ( supervisor )
00803 actmap->supervisorpasswordcrc.setEncoded( svpwd_enc );
00804 else
00805 actmap->supervisorpasswordcrc.reset();
00806 }
00807
00808 if ( id == 2 )
00809 help(50);
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820 if ( id == 10 ) {
00821 Password pwd;
00822 pwd.setUnencoded ( svpwd_plt );
00823 strcpy ( svpwd_enc, pwd.toString().c_str() );
00824 enablebutton ( 11 );
00825 }
00826
00827 if ( id == 100 ) {
00828 if ( !defaultSettings ) {
00829 enablebutton ( 101 );
00830 enablebutton ( 3 );
00831 enablebutton ( 8 );
00832 enablebutton ( 10 );
00833 enablebutton ( 11 );
00834 enablebutton ( 12 );
00835
00836 } else {
00837 disablebutton ( 101 );
00838 disablebutton ( 3 );
00839 disablebutton ( 8 );
00840 disablebutton ( 10 );
00841 disablebutton ( 11 );
00842 disablebutton ( 12 );
00843
00844 }
00845 }
00846 if ( id == 12 ) {
00847 CGameOptions::Instance()->defaultSuperVisorPassword = svpwd_enc;
00848 CGameOptions::Instance()->setChanged();
00849 }
00850 }
00851
00852
00853 void tmultiplayersettings :: setcoordinates ( void )
00854 {
00855 }
00856
00857 void tmultiplayersettings :: init ( void )
00858 {
00859 techlevel = 0;
00860
00861 strcpy ( svpwd_enc, CGameOptions::Instance()->getDefaultSupervisorPassword().toString().c_str() );
00862
00863 tdialogbox::init();
00864 x1 = 20;
00865 y1 = 10;
00866 xsize = 600;
00867 ysize = 460;
00868 title = "multiplayer settings";
00869
00870 replays = 1;
00871 supervisor = 0;
00872 defaultSettings = 1;
00873
00874 windowstyle &= ~dlg_in3d;
00875
00876 addbutton ( "~O~K", 10, ysize - 35, xsize / 2 - 5, ysize - 10, 0, 1 , 1, true );
00877 addkey ( 1, ct_enter );
00878 addbutton ( "help (~F1~)", xsize/2 + 5, ysize - 35, xsize -10, ysize - 10, 0, 1 , 2, true );
00879 addkey ( 2, ct_f1 );
00880
00881
00882 addbutton ( "use ~d~efault settings", 10, 60, xsize-10, 75, 3, 0, 100, true );
00883 addeingabe ( 100, &defaultSettings, black, dblue );
00884
00885 addbutton ( "enable ~r~eplays", 15, 120, xsize-15, 135, 3, 0 , 8, false );
00886 addeingabe ( 8, &replays, black, dblue );
00887
00888 addbutton ( "start with ~t~echlevel", 15 , 150, 100 , 170, 2, 3 , 3, false );
00889 addeingabe ( 3, &techlevel, 0, 255 );
00890
00891
00892 addbutton ( "enable ~s~upervisor", 20, 195, xsize-25, 210, 3, 3 , 101, false );
00893 addeingabe ( 101, &supervisor, black, dblue );
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 addbutton ( "modify game parameters", 20, ysize - 80, 160, ysize - 65, 0, 1 , 125, true );
00905
00906
00907 addbutton ( "supervisor password (plain text)", 20 , 220, 150 , 240, 1, 3 , 10, false );
00908 addeingabe ( 10, &svpwd_plt, 0, 900 );
00909
00910 addbutton ( "supervisor password (encoded)", 20 , 250, 150 , 270, 1, 3 , 11, false );
00911 addeingabe ( 11, &svpwd_enc, 0, 900 );
00912
00913 addbutton ( "~s~ave password as default supervisor passw.", 20, 280, xsize / 2 - 5 , 300, 0, 1 , 12, false );
00914
00915 buildgraphics();
00916
00917 rahmen3 ( "advanced options", x1 + 10, y1 + 100, x1 + xsize - 10, y1 + ysize - 45, 1 );
00918
00919 rahmen3 ( "supervisor", x1 + 15, y1 + 185, x1 + xsize - 15, y1 + ysize - 85, 1 );
00920
00921 status = 0;
00922 }
00923
00924
00925 void tmultiplayersettings :: run ( void )
00926 {
00927 mousevisible ( true );
00928 do {
00929 tdialogbox::run();
00930 } while ( !status );
00931 }
00932
00933
00934 tmultiplayersettings :: ~tmultiplayersettings ( )
00935 {
00936 }
00937
00938
00939 #endif
00940
00941 class tgiveunitawaydlg : public tdialogbox {
00942 int markedplayer;
00943 int status;
00944 void paintplayer ( int i );
00945 tfield* fld ;
00946 int num;
00947 int ply[8];
00948 int xs;
00949 public:
00950 void init ( tfield* fld );
00951 void run ( void );
00952 void buttonpressed ( int id );
00953 };
00954
00955
00956 void tgiveunitawaydlg :: paintplayer ( int i )
00957 {
00958 if ( i < 0 )
00959 return;
00960
00961 if ( i == markedplayer ) {
00962 bar ( x1 + 20, y1 + starty + xs + i * 40, x1 + xsize - 20, y1 + starty + 60 + i * 40, 20 + ply[i] * 8 );
00963 } else {
00964 bar ( x1 + 20, y1 + starty + xs + i * 40, x1 + xsize - 20, y1 + starty + 60 + i * 40, dblue );
00965 }
00966
00967 activefontsettings.color = black;
00968 activefontsettings.font = schriften.smallarial;
00969 activefontsettings.length = 0;
00970
00971 if ( ply[i] < 8 )
00972 showtext2 ( actmap->player[ply[i]].getName().c_str(), x1 + 60, y1 + starty + xs+17 + i * 40 - activefontsettings.font->height / 2 );
00973 else
00974 showtext2 ( "neutral", x1 + 60, y1 + starty + xs+17 + i * 40 - activefontsettings.font->height / 2 );
00975 }
00976
00977 void tgiveunitawaydlg :: init( tfield* fld )
00978 {
00979 this->fld = fld;
00980
00981 xs = 15;
00982
00983 num = 0;
00984 for ( int i = 0; i < 8; i++ )
00985 if ( actmap->player[i].exist() )
00986 if ( i != actmap->actplayer && actmap->player[actmap->actplayer].diplomacy.getState( i) >= PEACE )
00987 ply[num++] = i;
00988
00989 if ( fld->building )
00990 ply[num++] = 8;
00991
00992
00993 if ( !num ) {
00994 displaymessage("You don't have any allies", 1 );
00995 return;
00996 }
00997
00998
00999 tdialogbox::init();
01000
01001 xsize = 250;
01002 ysize = 110 + num * 40;
01003
01004 if ( fld->vehicle )
01005 title = "give unit to";
01006 else if ( fld->building )
01007 title = "give building to";
01008
01009 addbutton ( "~O~k", 10, ysize - 30, xsize/2 - 5, ysize - 10 , 0, 1, 1, true );
01010 addkey ( 1, ct_enter );
01011 addbutton ( "~C~ancel", xsize/2 + 5, ysize - 30, xsize-10 - 5, ysize - 10 , 0, 1, 2, true );
01012 addkey ( 2, ct_esc );
01013
01014
01015 if ( num == 1 )
01016 markedplayer = 0;
01017 else
01018 markedplayer = -1;
01019
01020 status = 0;
01021
01022
01023 buildgraphics();
01024
01025
01026 for ( int j = 0; j < num; j++ )
01027 paintplayer( j );
01028
01029 }
01030
01031 void tgiveunitawaydlg :: buttonpressed ( int id )
01032 {
01033 if ( id == 1 )
01034 if ( markedplayer >= 0 )
01035 status = 12;
01036 else
01037 displaymessage ( "please select the player you want to give your unit to",1);
01038 if ( id == 2 )
01039 status = 10;
01040 }
01041
01042
01043 void tgiveunitawaydlg :: run ( void )
01044 {
01045 if ( !num )
01046 return;
01047
01048 while ( mouseparams.taste )
01049 releasetimeslice();
01050
01051 mousevisible ( true );
01052 do {
01053 tdialogbox :: run ( );
01054
01055 int old = markedplayer;
01056 if ( taste == ct_up && markedplayer > 0 )
01057 markedplayer --;
01058
01059 if ( taste == ct_down && markedplayer < num-1 )
01060 markedplayer ++;
01061
01062 if ( mouseparams.taste == 1 )
01063 for ( int i = 0; i < num; i++ )
01064 if ( mouseinrect ( x1 + 20, y1 + starty + xs + i * 40, x1 + xsize - 20, y1 + starty + 60 + i * 40 ) )
01065 markedplayer = i;
01066
01067
01068 if ( old != markedplayer ) {
01069 paintplayer ( markedplayer );
01070 paintplayer ( old );
01071 }
01072 } while ( status < 10 );
01073
01074 if ( status == 12 ) {
01075 if ( fld->vehicle )
01076 fld->vehicle->convert ( ply[markedplayer] );
01077 else
01078 if ( fld->building )
01079 fld->building->convert ( ply[markedplayer] );
01080 logtoreplayinfo ( rpl_convert, fld->getContainer()->getPosition().x, fld->getContainer()->getPosition().y, (int) ply[markedplayer] );
01081 computeview( actmap );
01082 }
01083 }
01084
01085 void giveunitaway ( tfield* fld )
01086 {
01087 if ( ( fld->vehicle && fld->vehicle->color==actmap->actplayer*8) || (fld->building && fld->building->color == actmap->actplayer * 8 )) {
01088 tgiveunitawaydlg gua;
01089 gua.init ( fld );
01090 gua.run ();
01091 gua.done ();
01092 } else {
01093 dispmessage2( 450, NULL );
01094 while ( mouseparams.taste )
01095 releasetimeslice();
01096
01097 }
01098 }
01099
01100
01101 #define entervalue ct_space
01102 #if 0
01103 class tverlademunition : public tmunitionsbox {
01104 int abstand;
01105 int firstliney;
01106 int startx;
01107 int llength;
01108 int numlength;
01109 VehicleService::Target* target;
01110 Vehicle* source;
01111 vector<int> oldpos;
01112 vector<int> newpos;
01113 vector<int> displayed;
01114 int abbruch;
01115 VehicleService* serviceAction;
01116 int targetNWID;
01117
01118 public:
01119
01120 void init ( Vehicle* src, int _targetNWID, VehicleService* _serviceAction );
01121 virtual void run ( void );
01122 virtual void buttonpressed( int id );
01123 void zeichneschieberegler( int pos);
01124 void checkpossible( int pos );
01125 void setloading ( int pos );
01126 };
01127
01128
01129 void tverlademunition::init( Vehicle* src, int _targetNWID, VehicleService* _serviceAction )
01130 {
01131 targetNWID = _targetNWID;
01132 serviceAction = _serviceAction;
01133 source = src;
01134
01135 VehicleService::TargetContainer::iterator i = serviceAction->dest.find ( targetNWID );
01136 if ( i == serviceAction->dest.end() )
01137 throw ASCmsgException ( "tverlademunition::init / target not found" );
01138
01139 target = &(i->second);
01140
01141 tmunitionsbox::init();
01142 x1 = 40;
01143 xsize = 560;
01144 y1 = 55;
01145
01146 title = "transfer ammunition and resources";
01147 backgrnd = dblue;
01148 windowstyle = windowstyle ^ dlg_in3d;
01149
01150 firstliney = 120;
01151 abstand = 25;
01152 startx = 230;
01153 llength = xsize - startx - 90;
01154 numlength = 40;
01155 }
01156
01157
01158 void tverlademunition::buttonpressed( int id)
01159 {
01160 if (id == 1) {
01161
01162 abbruch = true;
01163 }
01164 }
01165
01166
01167 #define yoffset 105
01168 void tverlademunition::run(void)
01169 {
01170 if ( !target->service.size() ) {
01171 displaymessage ( "nothing to transfer", 1 );
01172 return;
01173 }
01174
01175 y1 = 20;
01176 ysize = 180 + abstand*target->service.size();
01177
01178
01179
01180
01181 int i = target->service.size();
01182
01183 addbutton("~l~oad",10,ysize - 40,xsize - 10,ysize - 10,0,1,1,true);
01184 addkey(1,ct_enter);
01185 buildgraphics();
01186
01187 rahmen(true,x1 + 10,y1 + 50,x1 + xsize - 10,y1 + ysize - 50);
01188
01189 activefontsettings.justify = lefttext;
01190 activefontsettings.font = schriften.smallarial;
01191 activefontsettings.length = 100;
01192
01193 int ix = fieldsizex;
01194
01195 if ( source )
01196 source->paint( getActiveSurface(), SPoint(startx+x1 - 60 , y1 + 55));
01197
01198
01199
01200 target->dest->paint( getActiveSurface(), SPoint(x1 + xsize - 30 - ix , y1 + 55));
01201
01202 int pos = 0;
01203 for (i = 0; i < target->service.size() ; i++)
01204 if ( target->service[i].type != VehicleService::srv_repair ) {
01205 activefontsettings.length = (x1 + startx - numlength - 10 ) - (x1 + 20 );
01206 const char* text;
01207 switch ( target->service[i].type ) {
01208 case VehicleService::srv_ammo : text = cwaffentypen[ target->dest->typ->weapons.weapon[ target->service[i].targetPos ].getScalarWeaponType() ];
01209 break;
01210 case VehicleService::srv_resource : text = resourceNames[target->service[i].targetPos];
01211 break;
01212 case VehicleService::srv_repair : text = "damage";
01213 break;
01214 }
01215 oldpos.push_back ( target->service[i].curAmount );
01216 newpos.push_back ( target->service[i].curAmount );
01217 displayed.push_back ( i );
01218
01219 showtext2( text,x1 + 20, y1 + firstliney + pos * abstand);
01220
01221 rahmen(true, x1 + startx - 11, y1 + firstliney - 2 + pos * abstand, x1 + startx + llength + 11,y1 + firstliney + 18 + pos * abstand);
01222 zeichneschieberegler(pos);
01223 pos++;
01224 }
01225
01226 if ( !pos ) {
01227 displaymessage ( "nothing to transfer", 1 );
01228 return;
01229 }
01230
01231 mousevisible(true);
01232 abbruch = 0;
01233
01234 int mp = 0;
01235 do {
01236 int op = mp;
01237 tmunitionsbox::run();
01238 switch (taste) {
01239
01240 case ct_up: {
01241 op = mp;
01242 if (mp > 0)
01243 mp--;
01244 else
01245 mp = displayed.size() - 1;
01246 }
01247 break;
01248
01249 case ct_down: {
01250 op = mp;
01251 if (mp >= displayed.size() - 1)
01252 mp = 0;
01253 else
01254 mp++;
01255 }
01256 break;
01257
01258 case ct_left:
01259 case ct_right: {
01260 int step = ( target->service[displayed[mp]].maxAmount - target->service[displayed[mp]].minAmount ) / 100;
01261 if ( step == 0 )
01262 step = 1;
01263 step = int( pow ( double(10), double(log10 (double(step)))));
01264
01265 oldpos[mp] = newpos[mp];
01266
01267 if( taste == ct_left )
01268 newpos[mp] -= step;
01269 else
01270 newpos[mp] += step;
01271
01272 checkpossible(mp);
01273 if (oldpos[mp] != newpos[mp] )
01274 setloading ( mp );
01275 }
01276 break;
01277
01278 }
01279
01280 if (taste == ct_esc) {
01281 abbruch = true;
01282 }
01283
01284 if (taste == entervalue) {
01285 mousevisible(false);
01286 oldpos[mp] = newpos[mp];
01287 bar(x1 + xsize - 60, y1 + firstliney + mp * abstand,x1 + xsize - 17,y1 + firstliney + 15 + mp * abstand, backgrnd);
01288 intedit( &newpos[mp], x1 + xsize - 60, y1 + firstliney + mp * abstand, 43, 0, 65535);
01289 checkpossible(mp);
01290 if ( oldpos[mp] != newpos[mp] )
01291 setloading ( mp );
01292 mousevisible(true);
01293 }
01294 if ( mp != op ) {
01295 mousevisible(false);
01296 if ( op >= 0 )
01297 xorrectangle(x1 + 15,y1 + firstliney - 5 + op * abstand,x1 + xsize - 15,y1 + firstliney - 5 + (op + 1) * abstand,14);
01298 op = mp;
01299 xorrectangle(x1 + 15,y1 + firstliney - 5 + op * abstand,x1 + xsize - 15,y1 + firstliney - 5 + (op + 1) * abstand,14);
01300 mousevisible(true);
01301 }
01302
01303 int mx = mouseparams.x;
01304 for (i = 0; i < displayed.size() ; i++) {
01305 if ((mouseparams.taste == 1) && mouseinrect ( x1 + startx - 10, y1 + firstliney + i * abstand, x1 + startx + llength + 10, y1 + firstliney + i * abstand + 20 )) {
01306 oldpos[i] = newpos[i];
01307 float p = float(mx - (startx + x1)) / llength;
01308 if (p < 0)
01309 p = 0;
01310
01311 if ( p > 1 )
01312 p = 1;
01313
01314 newpos[i] = int(p * target->service[displayed[i]].maxAmount);
01315
01316 if (newpos[i] > target->service[displayed[i]].maxAmount)
01317 newpos[i] = target->service[displayed[i]].maxAmount;
01318
01319 if (newpos[i] < target->service[displayed[i]].minAmount)
01320 newpos[i] = target->service[displayed[i]].minAmount;
01321
01322 checkpossible(i);
01323
01324 if (oldpos[i] != newpos[i]) {
01325 mousevisible(false);
01326 setloading ( i );
01327 mousevisible(true);
01328 }
01329 }
01330 }
01331
01332 } while ( abbruch==0 );
01333
01334 mousevisible(false);
01335
01336 }
01337
01338
01339
01340
01341
01342 void tverlademunition::zeichneschieberegler( int b )
01343 {
01344 int r = getmousestatus();
01345 if (r == 2)
01346 mousevisible(false);
01347
01348
01349 int sta, sto;
01350 if ( b == -1 ) {
01351 sta = 0;
01352 sto = displayed.size()-1;
01353 } else {
01354 sta = b;
01355 sto = b;
01356 }
01357
01358 for ( b = sta; b <= sto; b++ ) {
01359
01360 int l;
01361
01362 bar(x1 + xsize - 60, y1 + firstliney + b * abstand, x1 + xsize - 17,y1 + firstliney + 15 + b * abstand,backgrnd);
01363
01364 activefontsettings.justify = lefttext;
01365 activefontsettings.background = dblue;
01366 activefontsettings.length = numlength;
01367
01368 showtext2(strrr( target->service[displayed[b]].curAmount ),x1 + startx + llength + 15, y1 + firstliney + b * abstand);
01369
01370 if ( target->service[displayed[b]].maxAmount )
01371 l = x1 + startx + llength * oldpos[b] / target->service[displayed[b]].maxAmount;
01372 else
01373 l = x1 + startx ;
01374
01375 rectangle(l - 10, y1 + firstliney - 1 + b * abstand,l + 10,y1 + firstliney - 1 + b * abstand + 18,backgrnd);
01376
01377 if ( target->service[displayed[b]].maxAmount )
01378 l = x1 + startx + llength * target->service[displayed[b]].curAmount / target->service[displayed[b]].maxAmount;
01379 else
01380 l = x1 + startx ;
01381
01382 rahmen(false, l - 10,y1 + firstliney - 1 + b * abstand,l + 10,y1 + firstliney - 1 + b * abstand + 18);
01383
01384
01385
01386 showtext2(strrr( target->service[displayed[b]].orgSourceAmount - (target->service[displayed[b]].curAmount - newpos[b])), x1 + startx - numlength -15 ,y1 + firstliney + b * abstand);
01387
01388 }
01389
01390 if (r == 2)
01391 mousevisible(true);
01392 }
01393
01394
01395 void tverlademunition::checkpossible(int b)
01396 {
01397 if ( newpos[b] > target->service[displayed[b]].maxAmount )
01398 newpos[b] = target->service[displayed[b]].maxAmount;
01399
01400 if ( newpos[b] < target->service[displayed[b]].minAmount )
01401 newpos[b] = target->service[displayed[b]].minAmount;
01402 }
01403
01404
01405
01406 void tverlademunition::setloading( int pos )
01407 {
01408 serviceAction->execute ( source, targetNWID, -1, 2, displayed[pos], newpos[pos] );
01409 zeichneschieberegler ( -1 );
01410 }
01411
01412 #endif
01413
01414
01415 void showPlayerTime()
01416 {
01417 ASCString text;
01418
01419 int p = actmap->actplayer;
01420 for ( int i = 0; i < 8; i++ ) {
01421 if ( actmap->player[p].exist() && actmap->player[p].playTime.size() ) {
01422 text += actmap->player[p].getName();
01423 text += " completed turn no. ";
01424 text += strrr(actmap->player[p].playTime.rbegin()->turn);
01425 text += " using ASC ";
01426 text += getVersionString( actmap->player[p].ASCversion );
01427 text += "\non ";
01428 text += asctime ( localtime ( &actmap->player[p].playTime.rbegin()->date));
01429 text += "\n";
01430 }
01431
01432
01433 ++p;
01434 if ( p >= 8 )
01435 p = 0;
01436 }
01437
01438 ViewFormattedText vft( "Play Time Information", text, PG_Rect( -1, -1 , 500, 400 ));
01439 vft.Show();
01440 vft.RunModal();
01441 }
01442
01443 void displaywindspeed( void )
01444 {
01445 #ifdef WEATHERGENERATOR
01446 displaymessage2("wind speed is %d which equals %s fields / turn", actmap->weatherSystem->getCurrentWindSpeed(), strrrd8d ( actmap->weatherSystem->getCurrentWindSpeed() * maxwindspeed / 256 ));
01447 #else
01448 displaymessage2("wind speed is %d which equals %s fields / turn", actmap->weather.windSpeed, strrrd8d ( actmap->weather.windDirection * maxwindspeed / 256 ));
01449 #endif
01450 }
01451