-
Notifications
You must be signed in to change notification settings - Fork 0
/
exult.cc
3484 lines (3249 loc) · 95 KB
/
exult.cc
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
/**
** Exult.cc - Multiplatform Ultima 7 game engine
**
** Written: 7/22/98 - JSF
**/
/*
* Copyright (C) 1998-1999 Jeffrey S. Freedman
* Copyright (C) 2000-2012 The Exult Team
*
* 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; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifndef ALPHA_LINUX_CXX
# include <cstdlib>
# include <cctype>
#endif
#include "sdl-compat.h"
#include <SDL.h>
#ifndef XENON
#define Font _XFont_
#include <SDL_syswm.h>
#undef Font
#endif
#ifdef USE_EXULTSTUDIO /* Only needed for communication with exult studio */
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef WIN32
#include "windrag.h"
#elif defined(XWIN)
#include "xdrag.h"
#endif
#include "servemsg.h"
#include "objserial.h"
#include "server.h"
#include "chunks.h"
#include "chunkter.h"
#endif
#if (defined(USECODE_DEBUGGER) && defined(XWIN))
#include <csignal>
#endif
#ifdef UNDER_CE
#include <gx.h>
#endif
#include "Audio.h"
#include "Configuration.h"
#include "Gump_manager.h"
#include "Scroll_gump.h"
#include "actors.h"
#include "args.h"
#include "cheat.h"
#include "effects.h"
#include "exult.h"
#include "exultmenu.h"
#include "fnames.h"
#include "font.h"
#include "game.h"
#include "gamewin.h"
#include "gamemap.h"
#include "gump_utils.h"
#include "keyactions.h"
#include "keys.h"
#include "mouse.h"
#include "ucmachine.h"
#include "utils.h"
#include "version.h"
#include "u7drag.h"
#include "drag.h"
#include "palette.h"
#include "glshape.h"
#include "combat_opts.h"
#include "U7file.h"
#include "U7fileman.h"
#include "exult_flx.h"
#include "exult_bg_flx.h"
#include "exult_si_flx.h"
#include "crc.h"
#include "items.h"
#include "gamemgr/modmgr.h"
#include "AudioMixer.h"
#include "VideoOptions_gump.h"
#ifndef XENON
#include "filesys/OutputLogger.h"
#else
#include <xetypes.h>
#include <xenos/xe.h>
#include <xenos/xenos.h>
#include <xenos/edram.h>
#include <xenos/xenos.h>
// for gdb
#include <threads/threads.h>
#include <threads/gdb.h>
#include <network/network.h>
#include <libfat/fat.h>
#include <usb/usbmain.h>
#include <diskio/ata.h>
//#include <console/console.h>
#include <xenon_smc/xenon_smc.h>
#include <xenon_soc/xenon_power.h>
#include <sys/iosupport.h>
#include <xenon_sound/sound.h>
#include "XBOXdefs.h"
#endif
using namespace Pentagram;
#ifdef UNDER_CE
#include "Keyboard_gump.h"
#include "touchscreen.h"
#endif
#ifdef __IPHONEOS__
#include "iphone_gumps.h"
#endif
#ifndef UNDER_EMBEDDED_CE
using std::atof;
using std::cerr;
using std::cout;
using std::endl;
using std::atexit;
using std::exit;
using std::toupper;
using std::string;
using std::vector;
#endif
Configuration *config = 0;
KeyBinder *keybinder = 0;
GameManager *gamemanager = 0;
/*
* Globals:
*/
// ****** XBOX ******
SDL_Joystick * joy;
int joy_pause = 0;
int mouse_mode = 1;
// *****************
Game_window *gwin = 0;
quitting_time_enum quitting_time = QUIT_TIME_NO;
bool intrinsic_trace = false; // Do we trace Usecode-intrinsics?
int usecode_trace = 0; // Do we trace Usecode-instructions?
// 0 = no, 1 = short, 2 = long
bool combat_trace = false; // show combat messages?
// Save game compression level
int save_compression = 1;
bool ignore_crc = false;
const std::string c_empty_string;
#ifdef UNDER_CE
string WINCE_exepath;
bool minimized;
Keyboard_gump *gkeyboard;
clsTouchscreen *Touchscreen;
#endif
#ifdef __IPHONEOS__
KeyboardButton_gump *gkeybb;
SDL_Joystick *sdl_joy;
#endif
#if 0 && USECODE_DEBUGGER
bool usecode_debugging=false; // Do we enable the usecode debugger?
extern void initialise_usecode_debugger(void);
#endif
struct resolution {
int x;
int y;
int scale;
} res_list[] = {
#ifdef UNDER_CE
{ 240, 160, 1 },
{ 160, 240, 1 },
{ 240, 320, 1 },
{ 240, 160, 2 },
{ 160, 240, 2 },
{ 240, 320, 2 },
#endif
{ 320, 200, 1 },
{ 320, 240, 1 },
{ 400, 300, 1 },
{ 320, 200, 2 },
{ 320, 240, 2 },
{ 400, 300, 2 },
{ 512, 384, 1 },
{ 640, 480, 1 },
{ 720, 480, 1 },
{ 800, 600, 1 }
};
int num_res = sizeof(res_list)/sizeof(struct resolution);
int current_res = 0;
#ifdef XWIN
int xfd = 0; // X connection #.
static class Xdnd *xdnd = 0;
#elif defined(WIN32)
static HWND hgwin;
static class Windnd *windnd = 0;
#endif
/*
* Local functions:
*/
static int exult_main(const char *);
static void Init();
static int Play();
static int Get_click(int& x, int& y, char *chr, bool drag_ok, Paintable *p, bool rotate_colors = false);
static int find_resolution(int w, int h, int s);
static void set_resolution (int new_res, bool save);
#ifdef USE_EXULTSTUDIO
static void Move_dragged_shape(int shape, int frame, int x, int y,
int prevx, int prevy, bool show);
static void Move_dragged_combo(int xtiles, int ytiles, int tiles_right,
int tiles_below, int x, int y, int prevx, int prevy, bool show);
static void Drop_dragged_shape(int shape, int frame, int x, int y, void *d);
static void Drop_dragged_chunk(int chunknum, int x, int y, void *d);
static void Drop_dragged_npc(int npcnum, int x, int y, void *d);
static void Drop_dragged_combo(int cnt, U7_combo_data *combo,
int x, int y, void *d);
#endif
static void BuildGameMap(BaseGameInfo *game, int mapnum);
static void Handle_events();
static void Handle_event(SDL_Event& event);
/*
* Statics:
*/
static bool run_bg = false; // skip menu and run bg
static bool run_si = false; // skip menu and run si
static bool run_fov = false; // skip menu and run fov
static bool run_ss = false; // skip menu and run ss
static string arg_gamename = "default"; // cmdline arguments
static string arg_modname = "default"; // cmdline arguments
static string arg_configfile = "";
static int arg_buildmap = -1;
static int arg_mapnum = -1;
static bool arg_nomenu = false;
static bool arg_edit_mode = false; // Start up ExultStudio.
static bool arg_write_xml = false; // Write out game's config. as XML.
static bool dragging = false; // Object or gump being moved.
static bool dragged = false; // Flag for when obj. moved.
static bool right_on_gump = false; // Right clicked on gump?
static int show_items_x = 0, show_items_y = 0;
static unsigned int show_items_time = 0;
static bool show_items_clicked = false;
static int left_down_x = 0, left_down_y = 0;
#if (defined(XWIN) && HAVE_SIGNAL_H && HAVE_SYS_WAIT_H)
// a SIGCHLD handler to properly clean up forked playmidi processes (if any)
#include <sys/wait.h>
#include <signal.h>
void sigchld_handler(int sig)
{
waitpid(-1, 0, WNOHANG);
}
#endif
#if defined(_WIN32) && defined(main) && defined(_MSC_VER)
#undef main
#endif
#ifdef XENON
#define TR {printf("[Trace] in function %s, line %d, file %s\n",__FUNCTION__,__LINE__,__FILE__);}
static void findDevices()
{
int device_list_size = 0;
char device_list[STD_MAX][10];
int i;
for (i = 3; i < STD_MAX; i++)
{
if (devoptab_list[i]->structSize)
{
printf("findDevices : %s\r\n", devoptab_list[i]->name);
}
}
}
#endif
/*
* Main program.
*/
#ifndef XENON
int main
(
int argc,
char *argv[]
)
{
#else
#ifdef XENON
int main()
{
TR;
int argc=1;
char* argv[20]={"uda:/exult/exult.elf"};
try
{
//what the holy fuck is making this function fail
threading_init();
xenon_make_it_faster(XENON_SPEED_FULL);
TR;
xenos_init(VIDEO_MODE_AUTO);
// for GDB
network_init();
gdb_init();
//console_init();
TR;
xenon_sound_init();
// usb
TR;
usb_init();
TR;
xenon_ata_init();
TR;
usb_do_poll();
TR;
fatInitDefault();
TR;
findDevices();
TR;
}
catch( const exult_exception & e )
{
cerr << "============================" << endl <<
"An exception occured: " << endl <<
e.what() << endl <<
"errno: " << e.get_errno() << endl;
if( e.get_errno() != 0)
perror("Error Description");
cerr << "============================" << endl;
}
#endif
#endif
#ifdef BEOS
// get exult path
int counti;
char datapath[256];
for (counti=strlen(argv[0]) ; argv[0][counti]!='/' ; counti--);
strncpy(datapath, argv[0], counti);
chdir(datapath);
#endif
#if (defined(XWIN) && HAVE_SIGNAL_H && HAVE_SYS_WAIT_H)
signal(SIGCHLD, sigchld_handler);
#endif
bool needhelp=false;
bool showversion=false;
int result;
Args parameters;
// Declare everything from the commandline that we're interested in.
parameters.declare("-h",&needhelp,true);
parameters.declare("--help",&needhelp,true);
parameters.declare("/?",&needhelp,true);
parameters.declare("/h",&needhelp,true);
parameters.declare("--bg",&run_bg,true);
parameters.declare("--si",&run_si,true);
parameters.declare("--fov",&run_fov,true);
parameters.declare("--ss",&run_ss,true);
parameters.declare("--nomenu", &arg_nomenu, true);
parameters.declare("-v",&showversion,true);
parameters.declare("--version",&showversion,true);
parameters.declare("--game",&arg_gamename,"default");
parameters.declare("--mod",&arg_modname,"default");
parameters.declare("--buildmap",&arg_buildmap,-1);
parameters.declare("--mapnum",&arg_mapnum,-1);
parameters.declare("--nocrc",&ignore_crc,true);
parameters.declare("-c",&arg_configfile,"");
parameters.declare("--edit",&arg_edit_mode,true);
parameters.declare("--write-xml",&arg_write_xml,true);
#if defined WIN32
bool portable = false;
parameters.declare("-p",&portable,true);
#endif
// Process the args
parameters.process(argc,argv);
add_system_path("<alt_cfg>", arg_configfile.c_str());
#if defined WIN32
if (portable)
add_system_path("<HOME>", ".");
setup_program_paths();
redirect_output("std");
#endif
if(needhelp)
{
cerr << "Usage: exult [--help|-h] [-v|--version] [-c configfile]"<<endl
<< " [--bg|--fov|--si|--ss|--game <game>] [--mod <mod>]" << endl
<< " [--nomenu] [--buildmap 0|1|2] [--mapnum <num>]" << endl
<< " [--nocrc] [--edit] [--write-xml]" << endl
<< "--help\t\tShow this information" << endl
<< "--version\tShow version info" << endl
<< " -c configfile\tSpecify alternate config file" << endl
<< "--bg\t\tSkip menu and run Black Gate (prefers original game)" << endl
<< "--fov\t\tSkip menu and run Black Gate with Forge of Virtue expansion" << endl
<< "--si\t\tSkip menu and run Serpent Isle (prefers original game)" << endl
<< "--ss\t\tSkip menu and run Serpent Isle with Silver Seed expansion" << endl
<< "--nomenu\tSkip BG/SI game menu" << endl
<< "--game <game>\tRun original game" << endl
<< "--mod <mod>\tMust be used together with '--bg', '--fov', '--si', '--ss' or" << endl
<< "\t\t'--game <game>'; runs the specified game using the mod with" << endl
<< "\t\ttitle equal to '<mod>'" << endl
<< "--buildmap <N>\tCreate a fullsize map of the game world in u7map??.pcx" << endl
<< "\t\t(N=0: all roofs, 1: no level 2 roofs, 2: no roofs)" << endl
<< "\t\tOnly valid if used together with '--bg', '--fov', '--si', '--ss'" << endl
<< "\t\tor '--game <game>'; you may optionally specify a mod with" << endl
<< "\t\t'--mod <mod>' (WARNING: requires big amounts of RAM, HD" << endl
<< "\t\tspace and time!)" << endl
<< "--mapnum <N>\tThis must be used with '--buildmap'. Selects which map" << endl
<< "\t\t(for multimap games or mods) whose map is desired" << endl
<< "--nocrc\t\tDon't check crc's of .flx files" << endl
<< "--edit\t\tStart in map-edit mode" << endl
#if defined WIN32
<< " -p\t\tMakes the home path the Exult directory (old Windows way)" << endl
#endif
<< "--write-xml\tWrite 'patch/exultgame.xml'" << endl;
exit(1);
}
unsigned gameparam = (unsigned)run_bg +(unsigned)run_si
+ (unsigned)run_fov + (unsigned)run_ss
+ (unsigned)(arg_gamename != "default");
if (gameparam > 1)
{
cerr << "Error: You may only specify one of --bg, --fov, --si, --ss or --game!" <<
endl;
exit(1);
}
else if (arg_buildmap >= 0 && gameparam == 0)
{
cerr << "Error: --buildmap requires one of --bg, --fov, --si, --ss or --game!" <<
endl;
exit(1);
}
if (arg_mapnum >= 0 && arg_buildmap < 0)
{
cerr << "Error: '--mapnum' requires '--buildmap'!" << endl;
exit(1);
}
else if (arg_mapnum < 0)
arg_mapnum = 0; // Sane default.
if (arg_modname != "default" && !gameparam)
{
cerr << "Error: You must also specify the game to be used!" << endl;
exit(1);
}
if(showversion) {
getVersionInfo(cerr);
return 0;
}
try
{
result = exult_main("uda:/exult/");
}
catch( const quit_exception & /*e*/ )
{
Audio::Destroy(); // Deinit the sound system.
result = 0;
}
catch( const exult_exception & e )
{
cerr << "============================" << endl <<
"An exception occured: " << endl <<
e.what() << endl <<
"errno: " << e.get_errno() << endl;
if( e.get_errno() != 0)
perror("Error Description");
cerr << "============================" << endl;
}
return result;
}
#ifdef _WIN32
#include <windows.h>
#include <cstdio>
// From Pentagram:
PCHAR* CommandLineToArgvA
(
PCHAR CmdLine,
int* _argc
)
{
PCHAR* argv;
PCHAR _argv;
ULONG len;
ULONG argc;
CHAR a;
ULONG i, j;
BOOLEAN in_QM;
BOOLEAN in_TEXT;
BOOLEAN in_SPACE;
len = strlen(CmdLine);
i = ((len+2)/2)*sizeof(PVOID) + sizeof(PVOID);
argv = (PCHAR*)GlobalAlloc(GMEM_FIXED, i + (len+2)*sizeof(CHAR));
_argv = (PCHAR)(((PUCHAR)argv)+i);
argc = 0;
argv[argc] = _argv;
in_QM = FALSE;
in_TEXT = FALSE;
in_SPACE = TRUE;
i = 0;
j = 0;
while (a = CmdLine[i])
{
if (in_QM)
{
if (a == '\"')
in_QM = FALSE;
else
{
_argv[j] = a;
j++;
}
}
else
{
switch (a)
{
case '\"':
in_QM = TRUE;
in_TEXT = TRUE;
if (in_SPACE)
{
argv[argc] = _argv+j;
argc++;
}
in_SPACE = FALSE;
break;
case ' ':
case '\t':
case '\n':
case '\r':
if(in_TEXT)
{
_argv[j] = '\0';
j++;
}
in_TEXT = FALSE;
in_SPACE = TRUE;
break;
default:
in_TEXT = TRUE;
if(in_SPACE)
{
argv[argc] = _argv+j;
argc++;
}
_argv[j] = a;
j++;
in_SPACE = FALSE;
break;
}
}
i++;
}
_argv[j] = '\0';
argv[argc] = NULL;
(*_argc) = argc;
return argv;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
/* Pulled from SDL_win32_main.c; this comment is also theirs:
Start up DDHELP.EXE before opening any files, so DDHELP doesn't
keep them open. This is a hack.. hopefully it will be fixed
someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
*/
HMODULE hLib = LoadLibrary(TEXT("DDRAW.DLL"));
if (hLib != NULL)
FreeLibrary(hLib);
int argc;
char **argv = CommandLineToArgvA(GetCommandLineA(), &argc);
int res = main(argc, argv);
cleanup_output("std");
GlobalFree((HGLOBAL)argv);
return res;
}
#endif
/*
* Main program.
*/
int exult_main(const char *runpath)
{
#ifdef UNDER_CE
HWND RunningHandle = FindWindow(NULL, _T("Exult Ultima7 Engine"));
if (RunningHandle != NULL)
{// There's a minimized (probably) instance of Exult ... let's switch to it
//cerr << "ERROR: Already running. Switching to running instance..." << std::endl;
HWND OldHandle = GetForegroundWindow();
ShowWindow(RunningHandle, SW_RESTORE);
ShowWindow(OldHandle, SW_MINIMIZE);
return -1;
}
minimized = false;
#endif
string music_path;
// output version info
getVersionInfo(cout);
#ifdef UNDER_CE
WINCE_exepath = string(runpath).substr(0, string(runpath).find_last_of("\\")+1);
#endif
#ifndef WIN32
setup_program_paths();
#endif
// Read in configuration file
config = new Configuration;
if (arg_configfile != "") {
config->read_abs_config_file(arg_configfile);
} else {
#ifdef EASY_USER_CONFIGURATION_FILE
if (U7exists(EASY_USER_CONFIGURATION_FILE))
config->read_config_file(EASY_USER_CONFIGURATION_FILE);
else
config->read_config_file(USER_CONFIGURATION_FILE);
#else
config->read_config_file(USER_CONFIGURATION_FILE);
#endif
}
if (config->key_exists("config/gameplay/allow_double_right_move"))
{
string str;
config->value("config/gameplay/allow_double_right_move", str, "yes");
if (str == "no")
{
config->value("config/gameplay/allow_right_pathfind", str, "no");
config->set("config/gameplay/allow_right_pathfind", str, false);
}
config->remove("config/gameplay/allow_double_right_move",false);
}
// Setup virtual directories
string data_path;
config->value("config/disk/data_path",data_path,EXULT_DATADIR);
setup_data_dir(data_path, runpath);
std::string default_music = get_system_path("<DATA>/music");
config->value("config/disk/music_path",music_path,default_music.c_str());
add_system_path("<MUSIC>", music_path);
add_system_path("<STATIC>", "static");
add_system_path("<GAMEDAT>", "gamedat");
add_system_path("<PATCH>", "patch");
add_system_path("<SAVEGAME>", "savegame");
//add_system_path("<SAVEGAME>", ".");
add_system_path("<MODS>", "mods");
std::cout << "Exult path settings:" << std::endl;
std::cout << "Data : " << get_system_path("<DATA>") << std::endl;
std::cout << "Digital music : " << get_system_path("<MUSIC>") << std::endl;
std::cout << std::endl;
// Check CRCs of our .flx files
bool crc_ok = true;
const char *flexname = BUNDLE_CHECK(BUNDLE_EXULT_FLX, EXULT_FLX);
uint32 crc = crc32_syspath(flexname);
if (crc != EXULT_FLX_CRC32) {
crc_ok = false;
cerr << "exult.flx has a wrong checksum!" << endl;
}
flexname = BUNDLE_CHECK(BUNDLE_EXULT_BG_FLX, EXULT_BG_FLX);
if (U7exists(flexname)) {
if (crc32_syspath(flexname) != EXULT_BG_FLX_CRC32) {
crc_ok = false;
cerr << "exult_bg.flx has a wrong checksum!" << endl;
}
}
flexname = BUNDLE_CHECK(BUNDLE_EXULT_SI_FLX, EXULT_SI_FLX);
if (U7exists(flexname)) {
if (crc32_syspath(flexname) != EXULT_SI_FLX_CRC32) {
crc_ok = false;
cerr << "exult_si.flx has a wrong checksum!" << endl;
}
}
bool config_ignore_crc;
config->value("config/disk/no_crc",config_ignore_crc);
ignore_crc |= config_ignore_crc;
if (!ignore_crc && !crc_ok) {
cerr << "This usually means the file(s) mentioned above are "
<< "from a different version" << endl
<< "of Exult than this one. Please re-install Exult" << endl
<< endl
<< "(Note: if you modified the .flx files yourself, "
<< "you can skip this check" << endl
<< "by passing the --nocrc parameter.)" << endl;
return 1;
}
// Convert from old format if needed
vector<string> vs = config->listkeys("config/disk/game",false);
if (vs.size() == 0 && config->key_exists("config/disk/u7path"))
{
// Convert from the older format
string data_directory;
config->value("config/disk/u7path",data_directory,"./blackgate");
config->remove("config/disk/u7path",false);
config->set("config/disk/game/blackgate/path",data_directory,true);
}
// Enable tracing of intrinsics?
config->value("config/debug/trace/intrinsics",intrinsic_trace);
// Enable tracing of UC-instructions?
string uctrace;
config->value("config/debug/trace/usecode", uctrace, "no");
to_uppercase(uctrace);
if (uctrace == "YES")
usecode_trace = 1;
else if (uctrace == "VERBOSE")
usecode_trace = 2;
else
usecode_trace = 0;
config->value("config/debug/trace/combat",combat_trace);
// Save game compression level
config->value("config/disk/save_compression_level", save_compression, 1);
if (save_compression < 0 || save_compression > 2) save_compression = 1;
config->set("config/disk/save_compression_level", save_compression, false);
#if 0 && USECODE_DEBUGGER
// Enable usecode debugger
config->value("config/debug/debugger/enable",usecode_debugging);
initialise_usecode_debugger();
#endif
#if (defined(USECODE_DEBUGGER) && defined(XWIN))
signal(SIGUSR1, SIG_IGN);
#endif
cheat.init();
#ifdef UNDER_CE
GXOpenInput();
GXKeyList keys = GXGetDefaultKeys(GX_LANDSCAPEKEYS);
std::cout << "Up " << keys.vkUp << std::endl;
std::cout << "Down " << keys.vkDown << std::endl;
std::cout << "Left " << keys.vkLeft << std::endl;
std::cout << "Right " << keys.vkRight << std::endl;
std::cout << "A " << keys.vkA << std::endl;
std::cout << "B " << keys.vkB << std::endl;
std::cout << "C " << keys.vkC << std::endl;
std::cout << "Start " << keys.vkStart << std::endl;
gkeyboard = new Keyboard_gump();
Touchscreen = new clsTouchscreen();
#endif
#ifdef __IPHONEOS__
gkeybb = new KeyboardButton_gump();
#endif
Init(); // Create main window.
cheat.finish_init();
cheat.set_map_editor(arg_edit_mode); // Start in map-edit mode?
if (arg_write_xml)
game->write_game_xml();
Mouse::mouse = new Mouse(gwin);
Mouse::mouse->set_shape(Mouse::hand);
#ifdef UNDER_CE
gkeyboard->autopaint = false;
gkeyboard->minimize();
gkeyboard->autopaint = true;
#endif
#ifdef __IPHONEOS__
gkeybb->autopaint = true;
#endif
int result = Play(); // start game
#ifdef UNDER_CE
GXCloseInput();
#endif
#if defined(WIN32) && defined(USE_EXULTSTUDIO)
// Currently, leaving the game results in destruction of the window.
// Maybe sometime in the future, there is an option like "return to
// main menu and select another scenario". Becaule DnD isn't registered until
// you really enter the game, we remove it here to prevent possible bugs
// invilved with registering DnD a second time over an old variable.
RevokeDragDrop(hgwin);
delete windnd;
#endif
return result;
}
namespace ExultIcon {
#include "exulticon.h"
}
static void SetIcon()
{
SDL_Surface* iconsurface = SDL_CreateRGBSurfaceFrom(ExultIcon::header_data,
ExultIcon::width,
ExultIcon::height,
8,
ExultIcon::width,
0, 0, 0, 0);
SDL_Color iconpal[256];
for (int i = 0; i < 256; ++i) {
iconpal[i].r = ExultIcon::header_data_cmap[i][0];
iconpal[i].g = ExultIcon::header_data_cmap[i][1];
iconpal[i].b = ExultIcon::header_data_cmap[i][2];
}
SDL_SetPalette(iconsurface, SDL_LOGPAL, iconpal, 0, 256);
SDL_SetColorKey(iconsurface, SDL_SRCCOLORKEY, 0);
SDL_WM_SetIcon(iconsurface, 0);
SDL_FreeSurface(iconsurface);
}
/*
* Initialize and create main window.
*/
static void Init
(
)
{
Uint32 init_flags = SDL_INIT_JOYSTICK|SDL_INIT_VIDEO|SDL_INIT_TIMER; //|SDL_INIT_EVENTTHREAD;
#ifdef NO_SDL_PARACHUTE
init_flags |= SDL_INIT_NOPARACHUTE;
#endif
#ifdef WIN32
// Due to the new menu size, the window can sometimes
// be partially offscreen in Windows. SDL currently
// offers no better way of doing this, so...
// I don't know if this will be problem in other OSes,
// so I leave it Windows-specific for now.
// Maybe it would be best to use SDL_putenv instead?
SDL_putenv("SDL_VIDEO_CENTERED=center");
// Yes, SDL_putenv is GOOD. putenv does NOT work with wince. -PTG 2007/06/11
#elif defined(MACOSX) && defined(USE_EXULTSTUDIO)
// Just in case:
#ifndef XWIN
#error "Incompatible preprocessor definitions: simultaneous use of \"MACOSX\" and \"USE_EXULTSTUDIO\" require \"XWIN\" to be defined."
#endif
// Exult Studio support in Mac OS X is experimental and requires
// SDL to use X11. Hence, we force the issue.
SDL_putenv("SDL_VIDEODRIVER=x11");
#endif
#ifdef __IPHONEOS__
init_flags |= SDL_INIT_JOYSTICK;
#endif
if (SDL_Init(init_flags) < 0)
{
cerr << "Unable to initialize SDL: " << SDL_GetError() << endl;
exit(-1);
}
std::atexit(SDL_Quit);
#ifdef __IPHONEOS__
std::cout << "There are " << SDL_NumJoysticks() << " joystick(s) available" << std::endl;
std::cout << "Default joystick (index 0) is " << SDL_JoystickName(0) << std::endl;
sdl_joy = SDL_JoystickOpen(0);
if (sdl_joy == NULL)
std::cout << "Error: could not open joystick" << std::endl;
std::cout << "joystick number of axis: " << SDL_JoystickNumAxes(sdl_joy) << ", number of hats: " << SDL_JoystickNumHats(sdl_joy) << ", number of balls: " << SDL_JoystickNumBalls(sdl_joy) << ", number of buttons: " << SDL_JoystickNumButtons(sdl_joy) << std::endl;
#endif
#ifndef XENON
SDL_SysWMinfo info; // Get system info.
SDL_GetWMInfo(&info);
#endif
#ifdef USE_EXULTSTUDIO
// Want drag-and-drop events.
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
#endif
// KBD repeat should be nice.
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL);
SDL_ShowCursor(0);
#ifndef XENON
SDL_VERSION(&info.version);
#else
joy = SDL_JoystickOpen(0);
#endif
#ifndef MACOSX // Don't set icon on OS X; the external icon is *much* nicer
//SetIcon();
#endif
// Load games and mods; also stores system paths:
gamemanager = new GameManager();
if (arg_buildmap < 0)
{
string gr, gg, gb;
config->value("config/video/gamma/red", gr, "1.0");
config->value("config/video/gamma/green", gg, "1.0");
config->value("config/video/gamma/blue", gb, "1.0");
Image_window8::set_gamma((float)atof(gr.c_str()),
(float)atof(gg.c_str()), (float)atof(gb.c_str()));
string fullscreenstr; // Check config. for fullscreen mode.
config->value("config/video/fullscreen",fullscreenstr,"no");
bool fullscreen = (fullscreenstr=="yes");
config->set("config/video/fullscreen",fullscreen?"yes":"no",false);
int border_red, border_green, border_blue;
config->value("config/video/game/border/red", border_red, 0);
if (border_red<0) border_red = 0;
else if (border_red>255) border_red = 255;
config->set("config/video/game/border/red", border_red, false);
config->value("config/video/game/border/green", border_green, 0);
if (border_green<0) border_green= 0;
else if (border_green>255) border_green = 255;
config->set("config/video/game/border/green", border_green, false);
config->value("config/video/game/border/blue", border_blue, 0);
if (border_blue<0) border_blue = 0;
else if (border_blue>255) border_blue = 255;
config->set("config/video/game/border/blue", border_blue, false);
Palette::set_border(border_red,border_green,border_blue);
bool disable_fades;
config->value("config/video/disable_fades", disable_fades, false);
setup_video(fullscreen, VIDEO_INIT);
Audio::Init();
gwin->get_pal()->set_fades_enabled(!disable_fades);
gwin->set_in_exult_menu(false);
}
SDL_SETEVENTFILTER(0);
// Show the banner
game = 0;
do
{
reset_system_paths();
fontManager.reset();
U7FileManager::get_ptr()->reset();