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 "itemrepository.h"
00053 #include "strtmesg.h"
00054 #include "dialogs/editmapparam.h"
00055 #include "dlg_box.h"
00056 #include "spfst.h"
00057 #include "dialog.h"
00058 #include "actions/transfercontrolcommand.h"
00059 #include "widgets/textrenderer.h"
00060 #include "sg.h"
00061 #include "spfst-legacy.h"
00062
00063
00064 class ttributepayments : public tdialogbox {
00065 GameMap::ResourceTribute trib;
00066 int oldplayer;
00067 int player;
00068 void paintactplayer ( void );
00069 void paintvalues ( void );
00070 int status;
00071 int players[8];
00072 int wind1y, wind2y ;
00073 int wind1x, wind2x ;
00074
00075 public:
00076 void init ( void );
00077 void buttonpressed ( int id );
00078 void run ( void );
00079 };
00080
00081
00082 void ttributepayments :: init ( void )
00083 {
00084 int i;
00085
00086 tdialogbox::init();
00087 oldplayer = -1;
00088 player = 0;
00089 status = 0;
00090 xsize = 550;
00091 ysize = 400;
00092 title = "transfer resources";
00093
00094 trib = actmap->tribute;
00095
00096 memset ( &players, -1, sizeof( players ));
00097
00098 windowstyle &= ~dlg_in3d;
00099
00100 addbutton ( "~O~k", 10, ysize - 40, xsize/2 - 5, ysize - 10, 0, 1, 1, true );
00101 addkey ( 1, ct_enter );
00102
00103 addbutton ( "~C~ancel", xsize/2 + 5, ysize - 40, xsize-10 - 5, ysize - 10, 0, 1, 2, true );
00104 addkey ( 2, ct_esc );
00105
00106 wind1y = starty + 10;
00107
00108
00109
00110 buildgraphics();
00111
00112 for (i = 0; i < 3; i++)
00113 addbutton ( NULL, 250, wind1y + 15 + i * 40, 350, wind1y + 32 + i * 40, 2, 1, 3 + i, true );
00114
00115 int pos = 0;
00116 for ( i = 0; i < 8; i++ )
00117 if ( actmap->player[i].exist() )
00118 if ( i != actmap->actplayer )
00119 players[pos++] = i;
00120
00121
00122 activefontsettings.font = schriften.smallarial;
00123 activefontsettings.color = black;
00124 activefontsettings.length = 145 - 55;
00125 activefontsettings.justify = lefttext;
00126 activefontsettings.height = 0;
00127
00128 for ( i = 0; i < pos; i++) {
00129 bar ( x1 + 30, y1 + starty + 30 + i * 30, x1 + 50, y1 + starty + 50 + i * 30, 20 + players[i] * 8 );
00130 showtext2 ( actmap->player[players[i]].getName().c_str(), x1 + 55, y1 + starty + 30 + i * 30 );
00131 }
00132
00133 wind2y = starty + ( ysize - starty - 60 ) /2 + 5;
00134
00135 wind1x = 255 ;
00136 wind2x = 375 ;
00137
00138 rahmen ( true, x1 + 10, y1 + starty, x1 + xsize - 10, y1 + ysize - 50 );
00139 rahmen3 ( "player", x1 + 20, y1 + starty + 10, x1 + 150, y1 + ysize - 60, 1 );
00140
00141 rahmen3 ( "you send", x1 + 160, y1 + wind1y, x1 + wind2x - 10, y1 + wind2y - 10, 1 );
00142 rahmen3 ( "you still have outstanding", x1 + 160, y1 + wind2y, x1 + wind2x - 10, y1 + ysize - 60 , 1 );
00143
00144 rahmen3 ( "you have sent", x1 + wind2x - 5, y1 + wind1y, x1 + xsize - 20, y1 + wind2y - 10, 1 );
00145 rahmen3 ( "you got", x1 + wind2x - 5, y1 + wind2y, x1 + xsize - 20, y1 + ysize - 60 , 1 );
00146
00147
00148 activefontsettings.font = schriften.smallarial;
00149 activefontsettings.color = textcolor;
00150 activefontsettings.length = 0;
00151 activefontsettings.justify = lefttext;
00152 activefontsettings.height = 0;
00153
00154 for ( i = 0; i < 3; i++) {
00155 showtext2 ( resourceNames[i], x1 + 170, y1 + wind1y + 15 + i * 40 );
00156 showtext2 ( resourceNames[i], x1 + 170, y1 + wind2y + 15 + i * 40 );
00157
00158 rectangle ( x1 + wind2x, y1 + wind1y + 15 + i * 40, x1 + xsize - 30 , y1 + wind1y + 32 + i * 40, black );
00159 rectangle ( x1 + wind1x, y1 + wind2y + 15 + i * 40, x1 + wind2x - 15, y1 + wind2y + 32 + i * 40, black );
00160 rectangle ( x1 + wind2x, y1 + wind2y + 15 + i * 40, x1 + xsize - 30 , y1 + wind2y + 32 + i * 40, black );
00161 }
00162
00163 paintactplayer();
00164 paintvalues();
00165 }
00166
00167 void ttributepayments :: paintactplayer ( void )
00168 {
00169 int xx1 = x1 + 25;
00170 int xx2 = x1 + 145;
00171 int yy1 = y1 + starty + 25 + oldplayer * 30;
00172 int yy2 = yy1 + 30;
00173 if ( oldplayer != -1 )
00174 xorrectangle ( xx1, yy1, xx2, yy2, 14 );
00175
00176 yy1 = y1 + starty + 25 + player * 30;
00177 yy2 = yy1 + 30;
00178 if ( player != -1 )
00179 xorrectangle ( xx1, yy1, xx2, yy2, 14 );
00180
00181 oldplayer = player;
00182 }
00183
00184 void ttributepayments :: paintvalues ( void )
00185 {
00186 activefontsettings.font = schriften.smallarial;
00187 activefontsettings.color = textcolor;
00188 activefontsettings.justify = lefttext;
00189 activefontsettings.height = 0;
00190 activefontsettings.background = dblue;
00191
00192 for ( int i = 0; i < 3; i++) {
00193 addeingabe ( 3+i, &trib.avail[actmap->actplayer][players[player]].resource(i), 0, maxint );
00194 enablebutton ( 3+i );
00195
00196 activefontsettings.length = xsize - 40 - wind2x;
00197 showtext2 ( strrr ( trib.paid[actmap->actplayer][players[player]].resource(i)), x1 + wind2x + 5, y1 + wind2y + 16 + i * 40 );
00198 showtext2 ( strrr ( trib.paid[players[player]][actmap->actplayer].resource(i)), x1 + wind2x + 5, y1 + wind1y + 16 + i * 40 );
00199
00200 activefontsettings.length = wind2x - wind1x - 35;
00201 showtext2 ( strrr ( trib.avail[players[player]][actmap->actplayer].resource(i)), x1 + wind1x + 5, y1 + wind2y + 16 + i * 40 );
00202 }
00203 }
00204
00205
00206 void ttributepayments :: buttonpressed( int id )
00207 {
00208 tdialogbox::buttonpressed( id );
00209 if ( id == 1 )
00210 status = 11;
00211 if ( id == 2 )
00212 status = 10;
00213 }
00214
00215 void ttributepayments :: run ( void )
00216 {
00217 mousevisible(true);
00218 do {
00219 tdialogbox::run();
00220 if ( taste == ct_down ) {
00221 player++;
00222 if ( players[ player ] == -1 )
00223 player = 0;
00224 }
00225 if ( taste == ct_up ) {
00226 player--;
00227 if ( player < 0 )
00228 player = 7;
00229 while ( players[ player] == -1 )
00230 player--;
00231 }
00232 if ( mouseparams.taste & 1 )
00233 for (int i = 0; i < 8; i++) {
00234 if ( (mouseparams.x >= x1 + 25) &&
00235 (mouseparams.y >= y1 + starty + 25 + i * 30) &&
00236 (mouseparams.x <= x1 + 145) &&
00237 (mouseparams.y <= y1 + starty + 55 + i * 30 ) )
00238 if ( players[i] != -1 )
00239 player = i;
00240
00241 }
00242
00243 if ( player != oldplayer ) {
00244 paintactplayer();
00245 paintvalues();
00246 }
00247
00248 } while ( status < 10 );
00249
00250 if ( status >= 11 )
00251 actmap->tribute = trib;
00252 }
00253
00254
00255 void settributepayments ( void )
00256 {
00257 ttributepayments tpm;
00258 tpm.init();
00259 tpm.run();
00260 tpm.done();
00261 }
00262
00263
00264 class tresearchinfo: public tdialogbox {
00265 protected:
00266 int rppt;
00267 int status;
00268
00269
00270
00271 public:
00272 tresearchinfo ( void );
00273 void init ( void );
00274 void buttonpressed ( int id );
00275 void run ( void );
00276
00277 };
00278
00279 tresearchinfo::tresearchinfo ( void )
00280 {
00281 rppt = 0;
00282 status = 0;
00283 }
00284
00285 void tresearchinfo::init ( void )
00286 {
00287 tdialogbox::init();
00288 x1 = -1;
00289 y1 = -1;
00290 xsize = 500;
00291 ysize = 400;
00292 title = "research";
00293 addbutton ( "~O~K", 10, ysize - 30, xsize - 10, ysize - 10, 0, 1, 1, true );
00294 addkey( 1, ct_enter );
00295 addkey( 1, ct_esc );
00296 buildgraphics();
00297 rppt = actmap->player[actmap->actplayer].research.getResearchPerTurn();
00298 rahmen ( true, x1 + 19, y1 + 69, x1 + xsize - 19, y1 + 91 );
00299 bar ( x1 + 20, y1 + 70, x1 + xsize - 20, y1 + 90, dblue );
00300
00301 activefontsettings.font = schriften.smallarial;
00302 activefontsettings.color = textcolor;
00303 activefontsettings.justify = righttext;
00304 activefontsettings.length = 200;
00305 activefontsettings.background = 255;
00306
00307 int textxpos = x1 + xsize / 2 - 5 - activefontsettings.length;
00308
00309 showtext2 ( "name:", textxpos, y1 + 110 );
00310 showtext2 ( "research points:", textxpos, y1 + 140 );
00311 showtext2 ( "research points done:", textxpos, y1 + 170 );
00312 showtext2 ( "research points still needed:", textxpos, y1 + 200 );
00313 showtext2 ( "research done ( % ):", textxpos, y1 + 230 );
00314 showtext2 ( "research points / turn:", textxpos, y1 + 260 );
00315 showtext2 ( "time left (turns):", textxpos, y1 + 290 );
00316
00317
00318 activefontsettings.justify = lefttext;
00319 activefontsettings.length = 0;
00320 textxpos = x1 + xsize / 2 + 5 ;
00321 if ( actmap->player[actmap->actplayer].research.activetechnology ) {
00322 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 );
00323
00324
00325 int rp = actmap->player[actmap->actplayer].research.activetechnology->researchpoints;
00326 int prog = actmap->player[actmap->actplayer].research.progress;
00327 showtext2 ( actmap->player[actmap->actplayer].research.activetechnology->name, textxpos, y1 + 110 );
00328 showtext2 ( strrr ( rp ), textxpos, y1 + 140 );
00329 showtext2 ( strrr ( prog ), textxpos, y1 + 170 );
00330 showtext2 ( strrr ( rp - prog ), textxpos, y1 + 200 );
00331 if ( rp )
00332 showtext2 ( strrr ( 100 * prog / rp ), textxpos, y1 + 230 );
00333 if ( rppt )
00334 showtext2 ( strrr ( actmap->player[actmap->actplayer].research.currentTechAvailableIn() ), textxpos, y1 + 290 );
00335
00336 }
00337 showtext2 ( strrr ( rppt ), textxpos, y1 + 260 );
00338
00339
00340 }
00341
00342 void tresearchinfo::buttonpressed ( int id )
00343 {
00344 if ( id == 1 )
00345 status = 10;
00346 }
00347
00348 void tresearchinfo::run ( void )
00349 {
00350 mousevisible(true);
00351 do {
00352 tdialogbox::run();
00353 } while ( status < 10 );
00354 }
00355
00356
00357 void researchinfo ( void )
00358 { {
00359 tresearchinfo ri;
00360 ri.init();
00361 ri.run();
00362 ri.done();
00363 }
00364 {
00365 vector<ASCString> sv;
00366 for ( vector<int>::iterator i = actmap->player[actmap->actplayer].research.developedTechnologies.begin(); i != actmap->player[actmap->actplayer].research.developedTechnologies.end(); ++i ) {
00367 Technology* t = technologyRepository.getObject_byID( *i );
00368 if ( t )
00369 sv.push_back ( t->name );
00370 }
00371 sort ( sv.begin(), sv.end() );
00372
00373 ASCString s;
00374 for ( vector<ASCString>::iterator i = sv.begin(); i != sv.end(); ++i )
00375 s += *i + "\n";
00376
00377
00378 ViewFormattedText vft ( "Developed Technologies", s, PG_Rect( -1, -1, 500, 500 ));
00379 vft.Show();
00380 vft.RunModal();
00381
00382 }
00383 if ( skeypress( ct_lshift)) {
00384 ASCString s = actmap->player[actmap->actplayer].research.listTriggeredTechAdapter();
00385
00386 ViewFormattedText vft ( "Triggered TechAdapter", s, PG_Rect( -1, -1, 500, 500 ));
00387 vft.Show();
00388 vft.RunModal();
00389 }
00390
00391 }
00392
00393
00394
00395
00396
00397 class tchoosetechlevel : public tdialogbox {
00398 protected:
00399 int techlevel;
00400 int ok;
00401 public:
00402 void init ( void );
00403 void buttonpressed ( int id );
00404 void run ( void );
00405 };
00406
00407 void tchoosetechlevel :: init ( void )
00408 {
00409 tdialogbox :: init ( );
00410 title = "choose techlevel";
00411 xsize = 200;
00412 ysize = 150;
00413 techlevel = 0;
00414 ok = 0;
00415
00416 addbutton ( "~O~k", 10, ysize - 30, xsize - 10, ysize - 10 , 0, 1, 1, true );
00417 addkey ( 1, ct_enter );
00418
00419 addbutton ( "", 10, 60, xsize - 10, 85 , 2, 1, 2, true );
00420 addeingabe ( 2, &techlevel, 0, 255 );
00421 addkey ( 1, ct_space );
00422
00423 buildgraphics();
00424 }
00425
00426 void tchoosetechlevel :: buttonpressed ( int id )
00427 {
00428 tdialogbox:: buttonpressed ( id );
00429 if ( id == 1 )
00430 ok = 1;
00431 }
00432
00433 void tchoosetechlevel :: run ( void )
00434 {
00435 mousevisible ( true );
00436 do {
00437 tdialogbox::run();
00438 } while ( !ok );
00439 if ( techlevel > 0 )
00440 for ( int i = 0; i < 8; i++ )
00441 actmap->player[i].research.settechlevel ( techlevel );
00442
00443 };
00444
00445 void choosetechlevel ( void )
00446 {
00447 tchoosetechlevel ctl;
00448 ctl.init();
00449 ctl.run();
00450 ctl.done();
00451 }
00452
00453
00454
00455 #undef linelength
00456
00457
00458
00459 ASCString writeGameParametersToString ( GameMap* actmap )
00460 {
00461 ASCString s = "The game has been set up with the following game parameters:\n";
00462 s += "(black line: parameter has default value)\n\n";
00463 for ( int i = 0; i< gameparameternum; i++ ) {
00464
00465 int d = actmap->getgameparameter(GameParameter(i)) != gameParameterSettings[i].defaultValue;
00466
00467 if ( d )
00468 s+= "#color4#";
00469
00470 s += gameParameterSettings[i].longName;
00471 s += " = ";
00472 s += strrr ( actmap->getgameparameter(GameParameter(i)) );
00473
00474 if ( d )
00475 s+= "#color0#";
00476 s += "\n";
00477 }
00478 return s;
00479 }
00480
00481 void sendGameParameterAsMail ( GameMap* actmap )
00482 {
00483 ASCString s = writeGameParametersToString ( actmap );
00484
00485 if ( actmap->getgameparameter( cgp_superVisorCanSaveMap) ) {
00486 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"
00487 "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"
00488 "#color0# \n" + s;
00489 }
00490
00491 new Message ( s, actmap, 255 );
00492 }
00493
00494
00495 void showGameParameters ( void )
00496 {
00497 ViewFormattedText vft( "Game Parameters", writeGameParametersToString(actmap), PG_Rect( -1, -1, 500, 550 ) );
00498 vft.Show();
00499 vft.RunModal();
00500 }
00501
00502
00503
00504 class tgiveunitawaydlg : public tdialogbox {
00505 int markedplayer;
00506 int status;
00507 void paintplayer ( int i );
00508 MapField* fld ;
00509 int xs;
00510 TransferControlCommand::Receivers receivers;
00511 public:
00512 void init ( MapField* fld );
00513 void run ( const Context& context );
00514 void buttonpressed ( int id );
00515 };
00516
00517
00518 void tgiveunitawaydlg :: paintplayer ( int i )
00519 {
00520 if ( i < 0 )
00521 return;
00522
00523 if ( i == markedplayer ) {
00524 bar ( x1 + 20, y1 + starty + xs + i * 40, x1 + xsize - 20, y1 + starty + 60 + i * 40, 20 + receivers[i]->getPosition() * 8 );
00525 } else {
00526 bar ( x1 + 20, y1 + starty + xs + i * 40, x1 + xsize - 20, y1 + starty + 60 + i * 40, dblue );
00527 }
00528
00529 activefontsettings.color = black;
00530 activefontsettings.font = schriften.smallarial;
00531 activefontsettings.length = 0;
00532
00533 if ( receivers[i]->getPosition() < 8 )
00534 showtext2 ( receivers[i]->getName().c_str(), x1 + 60, y1 + starty + xs+17 + i * 40 - activefontsettings.font->height / 2 );
00535 else
00536 showtext2 ( "neutral", x1 + 60, y1 + starty + xs+17 + i * 40 - activefontsettings.font->height / 2 );
00537 }
00538
00539 void tgiveunitawaydlg :: init( MapField* fld )
00540 {
00541 this->fld = fld;
00542
00543 xs = 15;
00544
00545
00546 TransferControlCommand tcc( fld->getContainer() );
00547
00548 receivers = tcc.getReceivers();
00549
00550 tdialogbox::init();
00551
00552 xsize = 250;
00553 ysize = 110 + receivers.size() * 40;
00554
00555 if ( fld->vehicle )
00556 title = "give unit to";
00557 else if ( fld->building )
00558 title = "give building to";
00559
00560 addbutton ( "~O~k", 10, ysize - 30, xsize/2 - 5, ysize - 10 , 0, 1, 1, true );
00561 addkey ( 1, ct_enter );
00562 addbutton ( "~C~ancel", xsize/2 + 5, ysize - 30, xsize-10 - 5, ysize - 10 , 0, 1, 2, true );
00563 addkey ( 2, ct_esc );
00564
00565
00566 if ( receivers.size() == 1 )
00567 markedplayer = 0;
00568 else
00569 markedplayer = -1;
00570
00571 status = 0;
00572
00573
00574 buildgraphics();
00575
00576
00577 for ( int j = 0; j < receivers.size(); j++ )
00578 paintplayer( j );
00579
00580 }
00581
00582 void tgiveunitawaydlg :: buttonpressed ( int id )
00583 {
00584 if ( id == 1 ) {
00585 if ( markedplayer >= 0 )
00586 status = 12;
00587 else
00588 displaymessage ( "please select the player you want to give your unit to",1);
00589 }
00590
00591 if ( id == 2 )
00592 status = 10;
00593 }
00594
00595
00596 void tgiveunitawaydlg :: run ( const Context& context )
00597 {
00598 if ( !receivers.size() )
00599 return;
00600
00601 while ( mouseparams.taste )
00602 releasetimeslice();
00603
00604 mousevisible ( true );
00605 do {
00606 tdialogbox :: run ( );
00607
00608 int old = markedplayer;
00609 if ( taste == ct_up && markedplayer > 0 )
00610 markedplayer --;
00611
00612 if ( taste == ct_down && markedplayer < receivers.size()-1 )
00613 markedplayer ++;
00614
00615 if ( mouseparams.taste == 1 )
00616 for ( int i = 0; i < receivers.size(); i++ )
00617 if ( mouseinrect ( x1 + 20, y1 + starty + xs + i * 40, x1 + xsize - 20, y1 + starty + 60 + i * 40 ) )
00618 markedplayer = i;
00619
00620
00621 if ( old != markedplayer ) {
00622 paintplayer ( markedplayer );
00623 paintplayer ( old );
00624 }
00625 } while ( status < 10 );
00626
00627 if ( status == 12 ) {
00628 auto_ptr<TransferControlCommand> tcc ( new TransferControlCommand( fld->getContainer() ));
00629 tcc->setReceiver( receivers[markedplayer] );
00630 ActionResult res = tcc->execute( context );
00631 if ( res.successful() )
00632 tcc.release();
00633 else {
00634 displayActionError(res );
00635 }
00636 }
00637 }
00638
00639 void giveunitaway ( MapField* fld, const Context& context )
00640 {
00641 ContainerBase* c = fld->getContainer();
00642 if ( !c ) {
00643 dispmessage2( 450, NULL );
00644 return;
00645 }
00646
00647 if ( c->getOwner() != c->getMap()->actplayer ) {
00648 dispmessage2( 451, NULL );
00649 return;
00650 }
00651
00652 if ( TransferControlCommand::avail( c ) ) {
00653 tgiveunitawaydlg gua;
00654 gua.init ( fld );
00655 gua.run ( context );
00656 gua.done ();
00657 } else {
00658 dispmessage2( 450, NULL );
00659 while ( mouseparams.taste )
00660 releasetimeslice();
00661
00662 }
00663 }
00664
00665 void showPlayerTime()
00666 {
00667 ASCString text;
00668
00669 int p = actmap->actplayer;
00670 for ( int i = 0; i < 8; i++ ) {
00671 if ( actmap->player[p].exist() && actmap->player[p].playTime.size() ) {
00672 text += actmap->player[p].getName();
00673 text += " completed turn no. ";
00674 text += strrr(actmap->player[p].playTime.rbegin()->turn);
00675 text += " using ASC ";
00676 text += getVersionString( actmap->player[p].ASCversion );
00677 text += "\non ";
00678 text += asctime ( localtime ( &actmap->player[p].playTime.rbegin()->date));
00679 text += "\n";
00680 }
00681
00682
00683 ++p;
00684 if ( p >= 8 )
00685 p = 0;
00686 }
00687
00688 ViewFormattedText vft( "Play Time Information", text, PG_Rect( -1, -1 , 500, 400 ));
00689 vft.Show();
00690 vft.RunModal();
00691 }
00692
00693 void displaywindspeed( void )
00694 {
00695 #ifdef WEATHERGENERATOR
00696 displaymessage2("wind speed is %d which equals %s fields / turn", actmap->weatherSystem->getCurrentWindSpeed(), strrrd8d ( actmap->weatherSystem->getCurrentWindSpeed() * maxwindspeed / 256 ));
00697 #else
00698 displaymessage2("wind speed is %d which equals %s fields / turn", actmap->weather.windSpeed, strrrd8d ( actmap->weather.windDirection * maxwindspeed / 256 ));
00699 #endif
00700 }
00701