1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
|
/** \file edglobal.cpp
\brief various functions for the mapeditor
*/
/*
This file is part of Advanced Strategic Command; http://www.asc-hq.de
Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#include <stdarg.h>
#include "global.h"
#include "vehicletype.h"
#include "buildingtype.h"
#include "edmisc.h"
#include "loadbi3.h"
#include "edgen.h"
#include "edselfnt.h"
#include "edglobal.h"
#include "gameoptions.h"
#include "mapdisplay.h"
#include "itemrepository.h"
#include "clipboard.h"
#include "resourceplacementdialog.h"
#ifdef WEATHERGENERATOR
# include "weatherdialog.h"
#endif
#include "maped-mainscreen.h"
#include "attack.h"
#include "mapimageexport.h"
#include "viewcalculation.h"
#include "statistics.h"
#include "spfst-legacy.h"
#include "dialogs/unitinfodialog.h"
#include "dialogs/editmapparam.h"
#include "dialogs/alliancesetup.h"
#include "dialogs/playersetup.h"
#include "dialogs/editgameoptions.h"
#include "dialogs/admingame.h"
#include "dialogs/eventeditor.h"
#include "dialogs/newmap.h"
#include "dialogs/terraininfo.h"
#include "widgets/textrenderer.h"
#include "dialogs/exchangegraphics.h"
#include "dialogs/fileselector.h"
#include "dialogs/importbi3map.h"
#include "dialogs/unitguidedialog.h"
#include "dialogs/fileselector.h"
#include "stack.h"
const char* execactionnames[execactionscount] = {
"End MapEdit",
"Help",
"Goto EditMode",
"Select terrain",
"Select terrainAll",
"Select unit",
"Select color",
"Select building",
"Select object",
"Select objectAll",
"Select mine",
"Select weather",
"Setup alliances",
"Setup Players",
"Toggle ResourceMode",
"Change UnitDirection",
"Asc-Resource Mode",
"Write Map2PCX",
"Load map",
"Change players",
"New map",
"Goto PolygonMode",
"Rebuild Display",
"Open UnitInfo",
"View map",
"About",
"Create resources",
"View/Change cargo",
"View/Change resources",
"Change TerrainDirection",
"View/Change Events",
"Toggle Fillmode",
"Mapgenerator",
"Use active field values as selection",
"Delete active thing",
"Show palette",
"View/Change minestrength",
"View/Change mapvalues",
"View/Change production",
"Save map",
"View/Change item Values",
"Mirror CX-Pos",
"Mirror CY-Pos",
"Place mine",
"Place active thing",
"Delete Unit",
"Delete building",
"Delete selected object",
"Delete topmost object",
"Delete all objects",
"Delete mine",
"AboutBox",
"Save map as ...",
"End PolygonMode",
"Smooth coasts",
"Import BI-Map",
"SEPARATOR",
"BI-Resource Mode",
"Resize map",
"Insert BI map",
"Set zoom level",
"Move Building",
"set weather of whole map",
"set map parameters",
"terrain info",
"set unit filter",
"select graphic set",
"unitset transformation",
"Unitset Information",
"switch maps",
"transform map",
"Edit Map Archival Information",
"Display Resource Comparison",
"specify unit production",
"Paste",
"Copy",
"Cut",
"Save Clipboard",
"Load Clipboard",
"Set Turn Number",
"Show Pipeline Net",
"Edit Technologies",
"Edit ResearchPoints",
"Generate TechTree",
"Edit TechAdapter",
"Reset Player Data...",
"Fill map with resources",
"setup weather generation",
"Primary action",
"Reset Player Data...",
"View Player Strength",
"Increase Zoom",
"Decrease Zoom",
"Edit Preferences",
"Clear Mineral Resources",
"Dump Building definition",
"Dump Vehicle definition",
"Dump Object definition",
"PBP statistics",
"Exchange Graphics",
"Open Ctrl-key panel",
"Close Ctrl-key panel",
"Dump all vehicle definitions",
"Clear Selection",
"Dump all building definitions",
"Mirror map",
"Copy Area",
"Paste Area",
"Crash mapeditor",
"Test Debug Function",
"Unit Guide Dialog",
"Run Lua Script",
"Run Translation Script",
"Dump all Terrain",
"Dump all Objects",
"show weapon range"
};
SelectionHolder selection;
void SelectionHolder::setSelection( const Placeable& component )
{
delete currentItem;
currentItem = component.clone();
selectionChanged( currentItem );
}
void SelectionHolder::setPlayer( int player )
{
actplayer = player;
playerChanged( player );
if ( currentItem )
selectionChanged( currentItem );
}
void SelectionHolder::clear()
{
currentItem = NULL;
selectionChanged( NULL );
};
void SelectionHolder::setWeather( int weather )
{
currentWeather = weather;
if ( currentItem )
selectionChanged( currentItem );
}
const Placeable* SelectionHolder::getSelection()
{
return currentItem;
}
void SelectionHolder::pickup ( MapField* fld )
{
if ( fld->vehicle ) {
VehicleItem v ( fld->vehicle->typ );
actplayer = fld->vehicle->getOwner();
setSelection( v );
} else
if ( fld->building ) {
BuildingItem b ( fld->building->typ );
actplayer = fld->building->getOwner();
setSelection( b );
} else
if ( !fld->objects.empty() ) {
ObjectItem o ( fld->objects.begin()->typ );
setSelection( o );
} else {
TerrainItem t ( fld->typ->terraintype );
setSelection( t );
}
}
// � Infomessage
int infomessage( char* formatstring, ... )
{
char stringtooutput[200];
// int linenum = 0;
memset (stringtooutput, 0, sizeof ( stringtooutput ));
va_list paramlist;
va_start ( paramlist, formatstring );
vsprintf ( stringtooutput, formatstring, paramlist );
va_end ( paramlist );
npush ( activefontsettings );
activefontsettings.justify = lefttext;
activefontsettings.font = schriften.smallarial;
activefontsettings.color = lightgray;
activefontsettings.markcolor = red;
activefontsettings.background = 0;
activefontsettings.length = agmp->resolutionx - ( 640 - 387);
int yy = agmp->resolutiony - ( 480 - 450 );
showtext3c( stringtooutput, 37, yy );
npop( activefontsettings );
if ( formatstring == NULL || formatstring[0] == 0 )
lastdisplayedmessageticker = 0xffffff;
else
lastdisplayedmessageticker = ticker;
return ++actdisplayedmessage;
}
ASCString getbipath ( void )
{
ASCString filename = getbi3path();
appendbackslash( filename );
filename += "mis";
filename += pathdelimitterstring;
filename += "*.dat";
int cnt = 0;
while ( !exist ( filename )) {
filename = editString("enter Battle Isle path", filename );
if ( filename.empty() )
return "";
appendbackslash(filename);
CGameOptions::Instance()->BI3directory = filename;
CGameOptions::Instance()->setChanged ( 1 );
filename += "mis";
filename += pathdelimitterstring;
filename += "*.dat";
cnt++;
#if CASE_SENSITIVE_FILE_NAMES == 1
if (!exist ( filename ) && cnt == 1 )
displaymessage("The 'mis' and 'ger' / 'eng' directories must be lower case to import files from them !", 1 );
#endif
}
return getbi3path();
}
class PlayerColorPanel : public PG_Widget {
int openTime;
public:
PlayerColorPanel() : PG_Widget(NULL, PG_Rect(20,20,320,40))
{
int width = 30;
int gap = 5;
for ( int i = 0; i < max(actmap->getPlayerCount(),9); ++i ) {
PG_Widget* bar = new ColoredBar( actmap->getPlayer(i).getColor(), this, PG_Rect( gap + i * (width+gap), gap, width, width ));
PG_Label* lab = new PG_Label( bar, PG_Rect(5,5,width-10,width-10), ASCString::toString(i));
lab->SetFontSize(15);
}
PG_Application::GetApp()->sigAppIdle.connect( sigc::hide( sigc::mem_fun( *this, &PlayerColorPanel::idler )));
}
void Show( bool fade = false )
{
openTime = ticker;
PG_Widget::Show(fade);
}
void Hide( bool fade = false )
{
openTime = 0;
PG_Widget::Hide(fade);
}
bool eventKeyDown(const SDL_KeyboardEvent* key)
{
if ( key->keysym.sym >= '0' && key->keysym.sym <= '9' ) {
selection.setPlayer( key->keysym.sym - '0' );
return true;
}
Hide();
return false;
}
bool idler()
{
if ( !IsVisible() )
return false;
if ( !openTime )
return false;
if ( ticker > openTime + 200 ) {
Hide();
return true;
} else
return false;
}
};
void showPlayerPanel( bool open )
{
static PlayerColorPanel* pcp = NULL;
if ( open && !pcp )
pcp = new PlayerColorPanel();
if ( !pcp )
return;
if( open )
pcp->Show();
else
pcp->Hide();
}
int countPlayersBinary( const ContainerBase* cont )
{
int mask = 1 << cont->getOwner();
for ( ContainerBase::Cargo::const_iterator i = cont->getCargo().begin(); i != cont->getCargo().end(); ++i )
if ( *i )
mask |= countPlayersBinary( *i );
return mask;
}
int countPlayers( const ContainerBase* cont )
{
int res = countPlayersBinary( cont );
int count = 0;
for ( int i = 0; i < cont->getMap()->getPlayerCount(); ++i )
if ( res & (1 << i ))
++count;
return count;
}
void infoMessageClipboardPlayers(const ContainerBase* cont )
{
if ( countPlayers( cont ) > 1 )
infoMessage("Info: this unit/building contains cargo from other players");
}
// � ExecAction
//! this executes all functions that use legacy Eventhandling
void execaction( int code)
{
switch(code) {
case act_toggleresourcemode : {
if ( mainScreenWidget )
mainScreenWidget->toggleMapLayer( "resources");
displaymap();
}
break;
case act_asc_resource : {
actmap->_resourcemode = false;
displaymessage ( "ASC Resource mode enabled", 3 );
}
break;
case act_bi_resource : {
actmap->_resourcemode = true;
displaymessage ( "Battle Isle Resource mode enabled", 3 );
}
break;
case act_changeplayers : playerchange();
break;
/*
case act_polymode : {
getpolygon(&pfpoly);
if (pfpoly != NULL ) {
tfill = false;
polyfieldmode = true;
tchangepoly cp;
cp.poly = pfpoly;
cp.setpolytemps(1);
cursor.gotoxy(1,1);
displaymap();
pdbaroff();
}
}
break;
*/
case act_viewmap :
{
while (mouseparams.taste != 0)
releasetimeslice();
// showmap ();
displaymap();
}
break;
case act_changeunitdir : {
MapField* pf2 = getactfield();
if ( pf2 && pf2->vehicle ) {
pf2->vehicle->direction++;
if (pf2->vehicle->direction >= sidenum )
pf2->vehicle->direction = 0;
mapsaved = false;
displaymap();
}
}
break;
case act_changeresources : changeresource();
break;
case act_createresources : {
tputresourcesdlg prd;
prd.init();
prd.run();
prd.done();
if ( mainScreenWidget )
mainScreenWidget->activateMapLayer( "resources", true);
repaintMap();
}
break;
/*
case act_fillmode : if ( polyfieldmode == false ) {
if (tfill == true) tfill = false;
else tfill = true;
fillx1 = cursor.posx + actmap->xpos;
filly1 = cursor.posy + actmap->ypos;
pdbaroff();
}
break;
*/
case act_mapgenerator : mapgenerator();
break;
case act_setactivefieldvals : if ( getactfield() )
selection.pickup( getactfield() );
break;
case act_deletething : {
MapField* pf2 = getactfield();
mapsaved = false;
if (pf2 != NULL) {
if ( !removeCurrentItem() ) {
if (pf2->vehicle != NULL)
delete pf2->vehicle;
else
if (pf2->building != NULL)
delete pf2->building;
else
if ( !pf2->mines.empty() )
pf2->removemine( -1 );
else
pf2->removeObject( NULL );
}
mapsaved = false;
mapChanged( actmap );
}
}
break;
case act_deleteunit : {
MapField* pf2 = getactfield();
if (pf2 != NULL)
if (pf2->vehicle != NULL) {
delete pf2->vehicle;
mapsaved = false;
mapChanged( actmap );
}
}
break;
case act_deletebuilding : {
MapField* pf2 = getactfield();
if (pf2 != NULL)
if (pf2->building != NULL) {
delete pf2->building;
mapsaved = false;
mapChanged( actmap );
}
}
break;
case act_deleteobject :
case act_deletetopmostobject : {
MapField* pf2 = getactfield();
if ( pf2 ) {
mapsaved = false;
pf2->removeObject( NULL );
mapChanged( actmap );
}
}
break;
case act_deleteallobjects : {
MapField* pf2 = getactfield();
if ( pf2 ) {
mapsaved = false;
pf2->objects.clear( );
calculateallobjects( actmap );
mapChanged( actmap );
}
}
break;
case act_deletemine : {
MapField* pf2 = getactfield();
if (pf2 != NULL) {
mapsaved = false;
pf2->removemine( -1 );
mapChanged( actmap );
}
}
break;
case act_changeminestrength : changeminestrength();
break;
case act_changeunitvals : {
MapField* pf2 = getactfield();
if ( pf2 ) {
if ( pf2->vehicle ) {
changeunitvalues(pf2->vehicle);
displaymap();
}
else if ( pf2->building ) {
changebuildingvalues(*pf2->building);
} /* endif */
} /* endif */
}
break;
case act_mirrorcursorx : {
MapDisplayPG* md = getMainScreenWidget()->getMapDisplay();
md->cursor.goTo( MapCoordinate(actmap->xsize - md->cursor.pos().x, md->cursor.pos().y ) );
}
break;
case act_mirrorcursory : {
MapDisplayPG* md = getMainScreenWidget()->getMapDisplay();
md->cursor.goTo( MapCoordinate(md->cursor.pos().x, actmap->ysize - md->cursor.pos().y ) );
}
break;
// case act_placemine : placemine();
// break;
case act_placething : placeCurrentItem();
break;
/*
case act_endpolyfieldmode : {
if (polyfieldmode) {
polyfieldmode = false;
tchangepoly cp;
cp.poly = pfpoly;
cp.setpolytemps(0);
displaymap();
pdbaroff();
ch = 255;
}
}
break;
*/
case act_about :
case act_aboutbox : {
ASCString s = "#fontsize=22#Advanced Strategic Command\nMap Editor#fontsize=14#\n";
s += getVersionAndCompilation();
// s += "\n#fontsize=18#Credits#fontsize=14#\n";
s += readtextmessage( 1020 );
ViewFormattedText vft( "About", s, PG_Rect(-1,-1,450,550));
vft.Show();
vft.RunModal();
/*
help(1020);
tviewanytext vat;
ASCString msg = kgetstartupmessage();
vat.init ( "about", msg.c_str() );
vat.run();
vat.done();
*/
}
break;
case act_smoothcoasts : {
ForestCalculation::smooth ( 6, actmap, NULL );
displaymap();
}
break;
case act_resizemap : resizemap();
break;
case act_movebuilding: movebuilding();
break;
case act_setactweatherglobal: setweatherall ( selection.getWeather() );
displaymap();
break;
case act_terraininfo: viewterraininfo( actmap, actmap->getCursor(), true);
break;
case act_setunitfilter: selectunitsetfilter();
filtersChangedSignal();
break;
// case act_setzoom : choosezoomlevel();
// break;
case act_unitsettransformation: unitsettransformation();
break;
case act_unitSetInformation: viewUnitSetinfo();
break;
case act_primaryAction: if ( mapSwitcher.getDefaultAction() == MapSwitcher::select ) {
execaction ( act_setactivefieldvals );
execaction(act_switchmaps);
} else
execaction( act_placething );
break;
case act_switchmaps: mapSwitcher.toggle();
displaymap();
updateFieldInfo();
break;
case act_editArchivalInformation: editArchivalInformation();
break;
case act_displayResourceComparison : resourceComparison();
break;
/*
case act_specifyunitproduction: unitProductionLimitation();
break;
*/
case act_pasteFromClipboard: if ( getactfield() && !getactfield()->getContainer() ) {
ClipBoard::Instance().place( actmap->getCursor() );
mapsaved = false;
displaymap();
}
break;
case act_copyToClipboard: if ( getactfield() ) {
if ( getactfield()->vehicle ) {
ClipBoard::Instance().clear();
infoMessageClipboardPlayers( getactfield()->vehicle );
ClipBoard::Instance().addUnit( getactfield()->vehicle );
} else
if ( getactfield()->building ) {
ClipBoard::Instance().clear();
infoMessageClipboardPlayers( getactfield()->building );
ClipBoard::Instance().addBuilding( getactfield()->building );
}
}
break;
case act_cutToClipboard: if ( getactfield() ) {
if ( getactfield()->vehicle ) {
ClipBoard::Instance().clear();
infoMessageClipboardPlayers( getactfield()->vehicle );
ClipBoard::Instance().addUnit( getactfield()->vehicle );
execaction ( act_deleteunit );
mapsaved = false;
} else
if ( getactfield()->building ) {
ClipBoard::Instance().clear();
infoMessageClipboardPlayers( getactfield()->building );
ClipBoard::Instance().addBuilding( getactfield()->building );
execaction ( act_deletebuilding );
mapsaved = false;
}
}
break;
case act_saveClipboard: saveClipboard();
break;
case act_readClipBoard: readClipboard();
break;
case act_setTurnNumber: actmap->time.set ( getid("Turn",actmap->time.turn(),0,maxint), 0 );
break;
case act_showPipeNet: mainScreenWidget->getMapDisplay()->toggleMapLayer("pipes");
repaintMap();
break;
case act_editResearch: editResearch();
break;
case act_editResearchPoints: editResearchPoints();
break;
case act_generateTechTree: generateTechTree();
break;
case act_editTechAdapter: editTechAdapter();
break;
case act_playerStrengthSummary: pbpplayerstatistics( actmap );
break;
case act_unitGuideDialog: unitGuideWindow(2);
break;
}
}
//! this executes all functions that use Paragui Eventhandling
void execaction_pg(int code)
{
switch(code) {
#ifdef WEATHERGENERATOR
case act_setactnewweather: weatherConfigurationDialog();
break;
#endif
case act_selbodentyp : if ( mapSwitcher.getDefaultAction() == MapSwitcher::select )
execaction ( act_setactivefieldvals );
execaction( act_switchmaps);
break;
case act_selbodentypAll : mainScreenWidget->selectTerrainList();
break;
case act_selunit : mainScreenWidget->selectVehicle();
break;
case act_selbuilding : mainScreenWidget->selectBuilding();
break;
case act_selobject : mainScreenWidget->selectObject();
break;
case act_selobjectAll: mainScreenWidget->selectObjectList();
/* if ( mapSwitcher.getDefaultAction() == MapSwitcher::select )
execaction ( act_setactivefieldvals );
execaction( act_switchmaps);
*/
break;
case act_selmine : mainScreenWidget->selectMine();
break;
case act_unitinfo : unitInfoDialog();
break;
case act_setmapparameters: setmapparameters( actmap );
break;
case act_setupalliances : {
DirectAllianceSetupStrategy dass;
setupalliances( actmap, &dass, true );
}
break;
case act_setupplayers : setupPlayers( actmap, true );
break;
case act_loadmap : {
if (mapsaved == false )
if (choice_dlg("Map not saved ! Save now ?","~y~es","~n~o") == 1)
k_savemap(false);
try {
k_loadmap();
}
catch (ASCmsgException message ) {
errorMessage( "Could not load map:\n" + message.getMessage());
}
catch ( ... ) {
errorMessage ( "error loading file" );
}
displaymap();
}
break;
case act_savemap : k_savemap(false);
break;
case act_savemapas : k_savemap(true);
break;
case act_maptopcx : {
bool view = choice_dlg("Include view ?","~n~o", "~y~es") == 2;
if ( view )
computeview( actmap );
writemaptopcx ( actmap, view );
}
break;
case act_end : {
if ( mapSwitcher.getDefaultAction() == MapSwitcher::select )
execaction(act_switchmaps);
else
if (choice_dlg("Do you really want to quit ?","~y~es","~n~o") == 1) {
getPGApplication().Quit();
}
}
break;
case act_changecargo :
if ( getactfield() && getactfield()->getContainer() )
cargoEditor( getactfield()->getContainer() );
break;
case act_createresources2 : resourcePlacementDialog();
displaymap();
break;
case act_changeproduction : if ( getactfield() && getactfield()->getContainer() ) {
if ( getactfield()->getContainer()->baseType->hasFunction( ContainerBaseType::InternalVehicleProduction ))
editProduction( getactfield()->getContainer() );
else
warningMessage("this unit/building has no production capabilities");
}
break;
case act_selectgraphicset: selectgraphicset();
// showallchoices();
break;
case act_transformMap: transformMap();
break;
case act_increase_zoom:
if ( mainScreenWidget && mainScreenWidget->getMapDisplay() ) {
mainScreenWidget->getMapDisplay()->changeZoom( 10 );
viewChanged();
repaintMap();
}
break;
case act_decrease_zoom:
if ( mainScreenWidget && mainScreenWidget->getMapDisplay() ) {
mainScreenWidget->getMapDisplay()->changeZoom( -10 );
viewChanged();
repaintMap();
}
break;
case act_editpreferences:
editGameOptions( false );
break;
case act_events : eventEditor( actmap );
break;
case act_resetPlayerData: adminGame( actmap );
break;
case act_changemapvals : editMap(actmap);
break;
case act_newmap : newmap();
break;
case act_clearresources: {
for ( int y = 0; y < actmap->ysize; ++y)
for ( int x = 0; x < actmap->xsize; ++x ) {
actmap->getField(x,y)->fuel = 0;
actmap->getField(x,y)->material = 0;
}
repaintMap();
}
case act_dumpBuilding:
if ( getactfield() && getactfield()->building ) {
ASCString filename = selectFile( "*.dump", false );
if ( !filename.empty () ) {
tn_file_buf_stream stream ( filename, tnstream::writing );
PropertyWritingContainer pc ( "BuildingDump", stream );
actmap->getbuildingtype_byid(getactfield()->building->typ->id)->runTextIO( pc );
}
} else
errorMessage("no building selected");
break;
case act_dumpVehicle:
if ( getactfield() && getactfield()->vehicle ) {
ASCString filename = selectFile( "*.dump", false );
if ( !filename.empty () ) {
tn_file_buf_stream stream ( filename, tnstream::writing );
PropertyWritingContainer pc ( "VehicleDump", stream );
actmap->getvehicletype_byid(getactfield()->vehicle->typ->id)->runTextIO( pc );
}
} else
errorMessage("no vehicle selected");
break;
case act_dumpObject:
if ( getactfield() && !getactfield()->objects.empty() ) {
ASCString filename = selectFile( "*.dump", false );
if ( !filename.empty () ) {
tn_file_buf_stream stream ( filename, tnstream::writing );
PropertyWritingContainer pc ( "ObjectDump", stream );
actmap->getobjecttype_byid( getactfield()->objects.front().typ->id)->runTextIO( pc );
}
} else
errorMessage("no object selected");
break;
case act_help : help(1000);
break;
case act_pbpstatistics: pbpplayerstatistics( actmap );
break;
case act_exchangeGraphics: exchangeGraphics();
break;
case act_openControlPanel: showPlayerPanel(true);
break;
case act_releaseControlPanel: showPlayerPanel(false);
break;
case act_dumpAllVehicleDefinitions: {
StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "dumping all units" );
for ( int i = 0; i < vehicleTypeRepository.getNum(); ++i ) {
VehicleType* veh = vehicleTypeRepository.getObject_byPos( i );
tn_file_buf_stream stream ( "Vehicle" + ASCString::toString( i ) + ".dump", tnstream::writing );
PropertyWritingContainer pc ( "VehicleDump", stream );
veh->runTextIO( pc );
}
};
break;
case act_dumpAllBuildings: {
StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "dumping all buildings" );
for ( int i = 0; i < buildingTypeRepository.getNum(); ++i ) {
BuildingType* bld = buildingTypeRepository.getObject_byPos( i );
tn_file_buf_stream stream ( "Building" + ASCString::toString( i ) + ".dump", tnstream::writing );
PropertyWritingContainer pc ( "BuildingDump", stream );
bld->runTextIO( pc );
}
};
break;
case act_dumpAllTerrain: {
StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "dumping all terrain" );
for ( int i = 0; i < terrainTypeRepository.getNum(); ++i ) {
TerrainType* bld = terrainTypeRepository.getObject_byPos( i );
tn_file_buf_stream stream ( "terrain" + ASCString::toString( i ) + ".dump", tnstream::writing );
PropertyWritingContainer pc ( "terrainDump", stream );
bld->runTextIO( pc );
}
};
break;
case act_dumpAllObjects: {
ASCString text = "dumping all objects";
StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( text );
for ( int i = 0; i < objectTypeRepository.getNum(); ++i ) {
ObjectType* bld = objectTypeRepository.getObject_byPos( i );
tn_file_buf_stream stream ( "object" + ASCString::toString( i ) + ".dump", tnstream::writing );
PropertyWritingContainer pc ( "objectDump", stream );
bld->runTextIO( pc );
smw.SetText( text + ": " + ASCString::toString( int(i * 100 / objectTypeRepository.getNum() )) + "%" );
}
};
break;
case act_clearSelection: selection.clear();
break;
case act_locateItemByID: locateItemByID();
break;
case act_mirrorMap: mirrorMap();
break;
case act_copyArea: copyArea();
break;
case act_pasteArea: pasteArea();
break;
case asc_nullPointerCrash: {
char* p = NULL;
*p = 1;
}
break;
case asc_testFunction: testDebugFunction();
break;
case act_import_bi_map :
if (mapsaved == false )
if (choice_dlg("Map not saved ! Save now ?","~y~es","~n~o") == 1)
k_savemap(false);
importBI3Map( actmap );
displaymap();
break;
case act_insert_bi_map :
importBI3Map( actmap, true );
displaymap();
break;
case act_runLuaScript:
selectAndRunLuaScript( "*.lua" );
repaintMap();
break;
case act_runTranslationScript:
selectAndRunLuaScript( "*.map.*" );
repaintMap();
break;
case act_showweapnrange:
mainScreenWidget->showWeaponRange( actmap, actmap->getCursor() );
displaymap();
break;
};
}
void execaction_ev(int code)
{
execaction_pg(code);
execaction(code);
}
|