1 /*
2
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 */
19 /*
20 * $Source: r:/prj/cit/src/RCS/init.c $
21 * $Revision: 1.185 $
22 * $Author: xemu $
23 * $Date: 1994/11/28 06:38:07 $
24 */
25
26 #define __INIT_SRC
27
28 #include <string.h>
29 #include <stdio.h>
30
31 #include "Shock.h"
32 #include "InitMac.h"
33 #include "ShockDialogs.h"
34 #include "ShockBitmap.h"
35
36 #include "criterr.h"
37 #include "cybmem.h"
38 #include "cybrnd.h"
39 #include "drugs.h"
40 #include "frprotox.h"
41 #include "gamepal.h"
42 #include "gamestrn.h"
43 #include "gamescr.h"
44 #include "gamewrap.h"
45 #include "init.h"
46 #include "input.h"
47 #include "map.h"
48 #include "mfdext.h"
49 #include "musicai.h"
50 #include "objects.h"
51 #include "objsim.h"
52 #include "olhext.h"
53 #include "palfx.h"
54 #include "physics.h"
55 #include "player.h"
56 #include "render.h"
57 #include "rendtool.h"
58 #include "saveload.h"
59 #include "sideicon.h"
60 #include "splash.h" // for splash screen...
61 #include "statics.h"
62 #include "textmaps.h"
63 #include "tickcount.h"
64 #include "tools.h"
65 #include "gamerend.h"
66 #include "mainloop.h"
67 #include "game_screen.h"
68 #include "shodan.h"
69 #include "fullscrn.h"
70 #include "wares.h"
71 #include "frcamera.h"
72 #include "faketime.h"
73 #include "dynmem.h"
74 #include "citres.h"
75
76 #include "shockolate_version.h" // for system shock version number
77
78 #include "Modding.h"
79 #include <SDL.h>
80
81 /*
82 #define AIL_SOUND
83 #include "tminit.h"
84 #include "mlimbs.h"
85 #include "fault.h"
86 #include "dbg.h"
87 #include "config.h"
88 #include "memstat.h"
89 #include "lgprntf.h"
90
91 #include "anim.h"
92 #include "dpaths.h"
93 #include "setup.h"
94 #include "cutscene.h"
95 #include "bugtrak.h"
96 #include "btfunc.h"
97 #include "ai.h"
98
99 // TOTALLY TEMPORARY
100 #include "textmaps.h"
101
102 #include "obj3d.h" // for 3d base
103 #include "citmat.h" // for materials base
104 #include "version.h" // for system shock version number
105
106 #ifdef STARTUP_MEMSTATS
107 #include "mprintf.h"
108 #endif
109
110 #include "wsample.h"
111
112 #define CFG_LEVEL_VAR "LEVEL"
113 #define CFG_DEBUG_VAR "mono_debug"
114 #define CFG_NOFAULT_VAR "fault_off"
115 #define CFG_MEMCHECK_VAR "mem_check"
116 #define CFG_BUGTRAK_VAR "bugtrak"
117 #define CFG_BUGTRAK_RECORD_VAR "bugtrak_record"
118 #define CFG_ARCHIVE_VAR "archive"
119 #define CFG_SELFRUN_VAR "selfrun"
120 #define CFG_NORUN_VAR "norun"
121 #define CFG_HEAPCHECK_VAR "heap_checking"
122 #define CFG_EDMS_SANITY_VAR "edms_sanity"
123 #define CFG_OPTION_CURSOR_VAR "option_cursor_check"
124 #define CFG_SERIAL_SECRET "serial_mprint"
125 */
126 #define ORIGIN_DISPLAY_TIME (60 * 3)
127 #define LG_DISPLAY_TIME (60 * 3)
128 #define TITLE_DISPLAY_TIME (60 * 3)
129 #define MIN_WAIT_TIME (60)
130
131 //void DrawSplashScreen(short id, Boolean fadeIn);
132 void PreloadGameResources(void);
133 errtype init_gamesys();
134 errtype free_gamesys(void);
135 errtype init_load_resources();
136 errtype init_3d_objects();
137 errtype obj_3d_shutdown();
138 void init_popups();
139 uchar pause_for_input(ulong wait_time);
140 void shock_alloc_ipal();
141
142 extern void rendedit_process_tilemap(FullMap *fmap, LGRect *r, uchar newMap);
143 extern void mac_get_pal(int start, int n, uchar *pal_data);
144
145 errtype init_pal_fx();
146 void byebyemessage(void);
147 /*
148 errtype init_kb();
149 errtype init_debug();
150
151 extern void load_weapons_data(void);
152 extern errtype setup_init(void);
153 extern uchar toggle_heap_check(short keycode, ulong context, void *data);
154 */
155
156 extern errtype sanity_check_obj_props();
157 errtype amap_init(void);
158 // extern long old_ticks;
159
160 errtype object_data_load(void);
161 /*¥¥
162 int global_timer_id;
163 extern int mlimbs_peril;
164 */
165 uchar init_done = FALSE;
166 uchar clear_player_data = TRUE;
167 uchar objdata_loaded = FALSE;
168
169 /*
170 extern void (*enter_modes[])(void);
171
172 extern int KeyGetch(void);
173 extern void start_intro_sound(void);
174 extern void start_setup_sound(void);
175 extern void end_intro_sound(void);
176 extern void end_setup_sound(void);
177
178 extern void init_watchpoints(void);
179 */
180 extern void status_vitals_start(void);
181 extern void status_vitals_end(void);
182
183 uchar real_archive_fn[64];
184 /*
185 #define SPLASH_RES_FILE "splash.rsrc"
186 #ifndef EDITOR
187 #define MIN_SPLASH_TIME 1000
188 #else
189 #define MIN_SPLASH_TIME 0
190 #endif
191 */
192 MemStack temp_memstack;
193 #define TEMP_STACK_SIZE (16 * 1024)
194
pause_for_input(ulong wait_time)195 uchar pause_for_input(ulong wait_time) {
196 extern void pump_events(void);
197 bool gotInput = false;
198
199 ulong wait_until = TickCount() + wait_time;
200 while (!gotInput && ((ulong)TickCount() < wait_until)) {
201 pump_events();
202 SDLDraw();
203 }
204
205 // return if we got input
206 return (gotInput);
207 }
208
209 extern char which_lang;
210 int mfdart_res_file;
211 //#ifdef DEMO
212 // uchar *mfdart_files[] = { "mfdart.rsrc", "mfdart.rsrc", "mfdart.rsrc" };
213 //#else
214 char *mfdart_files[] = {"res/data/mfdart.res", "res/data/mfdfrn.res", "res/data/mfdger.res"};
215 //#endif
216
217 /* MLA - don't need these
218 extern void *CitMalloc(int n);
219 extern void CitFree(void *p);
220 */
221
222 #define PALETTE_SIZE 768
223 uchar ppall[PALETTE_SIZE];
224
225 //-------------------------------------------------
226 // Initialize everything!
227 //-------------------------------------------------
init_all(void)228 void init_all(void) {
229 /*
230 char buf[256];
231 char norun[1];
232 extern char savegame_dir[50];
233 extern Datapath savegame_dpath; */
234 ulong pause_time;
235 int i;
236 bool speed_splash = FALSE;
237 /*
238
239 uchar dofault = TRUE;
240 int dummy_count;
241 int data[1];
242 int cnt;
243 extern void init_config(int argc,char* argv[]);
244 extern errtype terrain_palette_popup(void);
245 extern uchar cam_mode;
246 */
247 extern void view360_init(void);
248 extern uchar *restemp_buffer;
249 extern int restemp_buffer_size;
250
251 start_mem = slorkatron_memory_check();
252 if (start_mem < MINIMUM_GAME_THRESHOLD)
253 critical_error(CRITERR_MEM | 1);
254
255 // register the bye message
256 atexit(byebyemessage);
257
258 ResInit();
259 // Where are these defined?
260 // restemp_buffer = ALTERNATE_BUFFER;
261 // restemp_buffer_size = ALTERNATE_BUFFER_SIZE;
262
263 /*
264 init_early_dpaths();
265 init_config(argc,argv);
266 if (config_get_raw(CFG_NORUN_VAR,norun,1))
267 {
268 if (norun[0]=='1')
269 critical_error(CRITERR_EXEC|1);
270 }
271 */
272 // Spew(DSRC_SYSTEM_Memory, ("initial memory: %d\n",start_mem));
273 /*
274 dofault = !config_get_raw(CFG_NOFAULT_VAR,NULL,0);
275 DBG(DSRC_SYSTEM_FaultDisable,{ dofault = FALSE;});
276 if (dofault)
277 ex_startup(EXM_ALL);
278 */
279 // KLC - this is done in uiInit() [in UI:EVENT.C] kb_startup(NULL);
280 // kb_set_state(0x54,KBA_SIGNAL);
281
282 // Use our own buffer for LZW
283 LzwSetBuffer((void *)big_buffer, BIG_BUFFER_SIZE);
284
285 // use it for rsd unpacking too....this might be fill'd with danger
286 gr_set_unpack_buf(big_buffer);
287
288 // set up temporary memory stuff
289 temp_memstack.baseptr = big_buffer + sizeof(big_buffer) - TEMP_STACK_SIZE;
290 temp_memstack.sz = TEMP_STACK_SIZE;
291 MemStackInit(&temp_memstack);
292 TempMemInit(&temp_memstack);
293
294 // initialize random seeds
295 rnd_init();
296
297 // initialize strings
298 init_strings();
299 // KLC - not in Mac version
300 // Initialize the Animation system
301 // AnimInit();
302
303 // Initialize low-level keyboard and mouse input. KLC - taken out of uiInit.
304 mouse_init(grd_cap->w, grd_cap->h);
305 kb_init(NULL);
306
307 // Initialize map
308 DEBUG("- Map Startup");
309 map_init();
310
311 DEBUG("- Physics Startup");
312 physics_init();
313 // KLC - done in InitMac.c.
314 // atexit(free_all);
315
316 DEBUG("- Load Resources");
317 init_load_resources();
318
319 DEBUG("- 3d Objects Startup");
320 init_3d_objects();
321
322 DEBUG("- Popups Startup");
323 init_popups();
324
325 DEBUG("- Gamesys Startup");
326 init_gamesys();
327
328 // Start up the 3d...
329 DEBUG("- Renderer Startup");
330 fr_startup();
331 game_fr_startup();
332
333 // initialize renderer
334 DEBUG("- SDL Startup");
335 InitSDL();
336
337 // Initialize the main game screen
338 DEBUG("- Main game screen Startup");
339 region_begin_sequence();
340
341 DEBUG("- Sound startup");
342 snd_startup();
343 snd_start_digital();
344 music_init();
345 digifx_init();
346
347 // Initialize the palette effects (for fades and color cycling)
348 DEBUG("- PAL startup");
349 palfx_init();
350
351 // Initialize animation callbacks
352 {
353 extern void init_animlist();
354 init_animlist();
355 }
356
357 // Play the Origin intro movie.
358 {
359 // FSSpec fSpec;
360 // FSMakeFSSpec(gDataVref, gDataDirID, "Origin", &fSpec);
361 // PlayStartupMovie(&fSpec, 0, 0);
362 }
363
364 DEBUG("- Screen init");
365 screen_init();
366 fullscreen_init();
367 amap_init();
368 init_side_icon_popups(); // KLC - new call.
369
370 DEBUG("- Input init");
371 init_input(); // KLC - moved here, after uiInit (in screen_init)
372
373 uiHideMouse(NULL); // KLC - added to hide mouse cursor
374
375 DEBUG("- VR init");
376 view360_init();
377 // KLC - no longer needed olh_init();
378
379 // Put up splash screen for US!
380 DEBUG("- Make splash");
381 uiFlush();
382
383 // DrawSplashScreen(REF_IMG_bmOriginSplash, TRUE);
384 // SDLDraw();
385
386 // Set the wait time for our screen
387 pause_time = TickCount();
388 if (!speed_splash)
389 pause_time += LG_DISPLAY_TIME;
390 else
391 pause_time += MIN_WAIT_TIME;
392
393 DEBUG("- Start vitals");
394 status_vitals_start();
395
396 for (i = 0; i < NUM_LOADED_TEXTURES; i++)
397 loved_textures[i] = i;
398
399 DEBUG("- Gamerenderer startup");
400 gamerend_init();
401
402 DEBUG("- Cameras startup");
403 init_hack_cameras();
404
405 DEBUG("- End Sequence");
406 region_end_sequence(FALSE);
407
408 DEBUG("- Lighting startup");
409 Init_Lighting();
410
411 // set default difficulty levels for player
412 for (i = 0; i < 4; i++)
413 player_struct.difficulty[i] = 2;
414
415 // KLC - no config stuff for Mac version
416 // if (!config_get_value(CFG_ARCHIVE_VAR, CONFIG_STRING_TYPE, &real_archive_fn, &dummy_count))
417 // BlockMove(ARCHIVE_FNAME, real_archive_fn, 20);
418
419 // KLC init_kb();
420 // KLC DbgInstallGetch(KeyGetch);
421
422 // Start out game with high peril, to sound cool...
423 mlimbs_peril = 95;
424
425 // LG splash screen wait
426 // pause_for_input(pause_time);
427 // speed_splash = TRUE;
428
429 init_pal_fx();
430
431 // Put up title screen
432 uiFlush();
433
434 // Preload and lock resources that are used often in the game.
435
436 PreloadGameResources();
437
438 // Draw something to avoid startup flash
439 gr_clear(0x00);
440 SDLDraw();
441
442 // set the wait time for system shock title screen
443
444 pause_time = TickCount();
445
446 if (!speed_splash)
447 pause_time += TITLE_DISPLAY_TIME;
448 else
449 pause_time += MIN_WAIT_TIME;
450
451 if ((_current_loop != SETUP_LOOP) && (_current_loop != CUTSCENE_LOOP)) {
452 //¥¥ for now object_data_load();
453
454 // gr_clear(0xFF);
455 // gr_set_pal(0, 256, ppall);
456 }
457
458 // perhaps shouldnt do this if we are going to go into editor...
459 // fade down for last time
460 if (_current_loop != EDIT_LOOP) {
461 // pause_for_input(TickCount() + 10);
462 // if (pal_fx_on)
463 // palfx_fade_down();
464 }
465
466 uiFlush();
467 init_done = TRUE;
468 }
469
470 /*
471 //-----------------------------------------------------------
472 // Draw a splash screen in its associated color table.
473 //-----------------------------------------------------------
474 void DrawSplashScreen(short id, Boolean fadeIn) {
475 byte pal_id;
476 uchar savep[768];
477 grs_bitmap bits;
478 // CTabHandle ctab;
479 extern void finish_pal_effect(byte id);
480 extern byte palfx_start_fade_up(uchar * new_pal);
481
482 // gr_clear(0xFF);
483
484 // First, clear the screen and load in the color table for this picture.
485 // gr_clear(0xFF);
486 ctab = GetCTable(id); // Get the pict's
487 CLUT if (ctab)
488 {
489 BlockMove((**(ctab)).ctTable, (**(gMainColorHand)).ctTable, 256 * sizeof(ColorSpec));
490 SetEntries(0, 255, (**(gMainColorHand)).ctTable);
491 ResetCTSeed();
492 DisposCTable(ctab);
493
494 #ifdef DO_FADES
495 if (fadeIn) // Get it in a form for
496 palette fade
497 {
498 mac_get_pal(0, 256, savep);
499 gr_set_pal(0, 256, savep);
500 }
501 #endif
502 LoadPictShockBitmap(&gMainOffScreen, id);
503
504 #ifdef DO_FADES
505 if (fadeIn)
506 pal_id = palfx_start_fade_up(savep);
507 #endif
508 gr_init_bm(&bits, (uchar *)gMainOffScreen.Address, BMT_FLAT8, 0, 640, 480);
509 gr_bitmap(&bits, 0, 0);
510
511 #ifdef DO_FADES
512 if (fadeIn)
513 finish_pal_effect(pal_id);
514 #endif
515 }
516 }
517 */
518
PreloadGameResources(void)519 void PreloadGameResources(void) {
520 // Images
521 ResLock(RES_gamescrGfx);
522
523 // Fonts
524 ResLock(RES_tinyTechFont);
525 ResLock(RES_doubleTinyTechFont);
526 ResLock(RES_citadelFont);
527 ResLock(RES_mediumLEDFont);
528
529 // Strings
530 ResLock(RES_objlongnames);
531 ResLock(RES_traps);
532 ResLock(RES_words);
533 ResLock(RES_texnames);
534 ResLock(RES_texuse);
535 ResLock(RES_inventory);
536 ResLock(RES_objshortnames);
537 ResLock(RES_HUDstrings);
538 ResLock(RES_lognames);
539 ResLock(RES_messages);
540 ResLock(RES_plotware);
541 ResLock(RES_screenText);
542 ResLock(RES_cyberspaceText);
543 ResLock(RES_accessCards);
544 ResLock(RES_miscellaneous);
545 ResLock(RES_games);
546 }
547
object_data_flush(void)548 void object_data_flush(void) {
549 if (!objdata_loaded)
550 return;
551
552 free_dynamic_memory(DYNMEM_ALL);
553 objdata_loaded = FALSE;
554 obj_shutdown();
555 }
556
object_data_load(void)557 errtype object_data_load(void) {
558 LGRect bounds;
559 extern cams objmode_cam;
560
561 // char buf[256];
562 // MemStat data;
563 // extern Datapath savegame_dpath;
564
565 if (objdata_loaded)
566 return (ERR_NOEFFECT);
567
568 // if(MemStats(&data))
569 // {
570 // Warning(("Heap is bad before starting object_data_load\n"));
571 // critical_error(CRITERR_MEM|7);
572 // }
573 // mprintf("Hey we have %d memory avail before object data load\n", data.free.sizeTot);
574
575 // KLC - Mac cursor showing at this time begin_wait();
576
577 // Initialize DOS (Doofy Object System)
578 DEBUG("ObjsInit");
579 ObjsInit();
580
581 obj_init();
582
583 // initialize player struct
584 DEBUG("Initialize player");
585 if (clear_player_data)
586 init_player(&player_struct);
587 clear_player_data = TRUE;
588
589 // Start up some subsystems
590 DEBUG("init mfd");
591 init_newmfd();
592
593 /*
594 // strcpy(buf,"DATA\\");
595 strcpy(buf,"");
596 // NOTE: is there any other loop we start in which doesnt overwrite the map
597 // if not
598 */
599 bounds.ul.x = bounds.ul.y = 0;
600 bounds.lr.x = global_fullmap->x_size;
601 bounds.lr.y = global_fullmap->y_size;
602
603 DEBUG("process tilemap");
604 rendedit_process_tilemap(global_fullmap, &bounds, TRUE);
605
606 // Make the objmode camera....
607 DEBUG("create camera");
608 fr_camera_create(&objmode_cam, CAMTYPE_OBJ, player_struct.rep, NULL, NULL);
609
610 DEBUG("load_dynamic_memory");
611 objdata_loaded = TRUE;
612 load_dynamic_memory(DYNMEM_ALL);
613
614 // KLC end_wait();
615 return (OK);
616 }
617
618 #ifdef DUMMY ///Â¥
619
init_kb()620 errtype init_kb() {
621 // Keyboard frobbing
622 if (config_get_raw(CHAINING_VAR, NULL, 0))
623 kb_set_flags(kb_get_flags() | KBF_CHAIN);
624 kb_set_state(0x16, KBA_REPEAT);
625 kb_set_state(0x17, KBA_REPEAT);
626 kb_set_state(0x18, KBA_REPEAT);
627 kb_set_state(0x1A, KBA_REPEAT);
628 kb_set_state(0x1B, KBA_REPEAT);
629 kb_set_state(0x24, KBA_REPEAT);
630 kb_set_state(0x25, KBA_REPEAT);
631 kb_set_state(0x26, KBA_REPEAT);
632 kb_set_state(0x09, KBA_REPEAT);
633 kb_set_state(0x33, KBA_REPEAT);
634 kb_set_state(0x32, KBA_REPEAT);
635 kb_set_state(0x34, KBA_REPEAT);
636 return (OK);
637 }
638
639 #endif // ¥ DUMMY
640
load_da_palette(void)641 errtype load_da_palette(void) {
642 int pal_file;
643
644 pal_file = ResOpenFile("res/data/gamepal.res");
645 if (pal_file < 0)
646 critical_error(CRITERR_RES | 4);
647 ResExtract(RES_gamePalette, FORMAT_RAW, ppall);
648 ResCloseFile(pal_file);
649 gr_set_pal(0, 256, ppall);
650
651 return (OK);
652 }
653
init_pal_fx()654 errtype init_pal_fx() {
655 int i;
656 FILE *ipalHdl;
657
658 i = 1;
659
660 // gr_clear(0xFF);
661
662 // Initialize the palette
663 load_da_palette();
664
665 // if we arent doing tlucs from a file
666 gr_alloc_tluc8_spoly_table(16);
667
668 // alloc ipal after the above - since we free ipal earlier
669 // prevents fragmenting a bit
670 shock_alloc_ipal();
671 // ipalHdl = shock_alloc_ipal();
672
673 for (i = 0; i < 16; i++)
674 gr_init_tluc8_spoly_table(i, fix_make(0, 0xe000), fix_make(0, 0x8000), gr_bind_rgb(255, 64, 64),
675 gr_bind_rgb(127 + (i << 3), 127 + (i << 3), 127 + (i << 3)));
676
677 #ifdef OLD_TLUCS
678 gr_make_tluc8_table(255, fix_make(0, 0x8000), fix_make(0, 0x8000), gr_bind_rgb(255, 0, 0));
679 gr_make_tluc8_table(254, fix_make(0, 0x8000), fix_make(0, 0x8000), gr_bind_rgb(0, 255, 0));
680 gr_make_tluc8_table(253, fix_make(0, 0x8000), fix_make(0, 0x8000), gr_bind_rgb(0, 0, 255));
681 gr_make_tluc8_table(252, fix_make(0, 0x8000), fix_make(0, 0x8000), gr_bind_rgb(80, 80, 80));
682 gr_make_tluc8_table(251, fix_make(0, 0x8000), fix_make(0, 0x8000), gr_bind_rgb(255, 255, 255));
683 gr_make_tluc8_table(250, fix_make(0, 0x8000), fix_make(0, 0x8000), gr_bind_rgb(0, 0, 0));
684 #else
685
686 #define CIT_FOG_OPAC fix_make(0, 0x3000)
687 #define CIT_FOG_PURE fix_make(0, 0x6000)
688
689 #define CIT_FORCE_OPAC fix_make(0, 0x5000)
690 #define CIT_FORCE_PURE fix_make(0, 0x8000)
691
692 gr_make_tluc8_table(249, CIT_FOG_OPAC, CIT_FOG_PURE, gr_bind_rgb(255, 0, 0));
693 gr_make_tluc8_table(250, CIT_FOG_OPAC, CIT_FOG_PURE, gr_bind_rgb(0, 255, 0));
694 gr_make_tluc8_table(251, CIT_FOG_OPAC, CIT_FOG_PURE, gr_bind_rgb(0, 0, 255));
695 gr_make_tluc8_table(248, CIT_FOG_OPAC, CIT_FOG_PURE, gr_bind_rgb(170, 170, 170));
696 gr_make_tluc8_table(252, CIT_FOG_OPAC, CIT_FOG_PURE, gr_bind_rgb(240, 240, 240));
697 gr_make_tluc8_table(247, CIT_FOG_OPAC, CIT_FOG_PURE, gr_bind_rgb(120, 120, 120));
698
699 gr_make_tluc8_table(255, CIT_FORCE_OPAC, CIT_FORCE_PURE, gr_bind_rgb(255, 0, 0));
700 gr_make_tluc8_table(254, CIT_FORCE_OPAC, CIT_FORCE_PURE, gr_bind_rgb(0, 255, 0));
701 gr_make_tluc8_table(253, CIT_FORCE_OPAC, CIT_FORCE_PURE, gr_bind_rgb(0, 0, 255));
702 #endif
703
704 {
705 extern uchar _g3d_enable_blend;
706 uchar tmppal_lower[32 * 3];
707 extern uchar ppall[]; // pointer to main shadow palette
708
709 _g3d_enable_blend = (start_mem >= BLEND_THRESHOLD);
710 if (_g3d_enable_blend) {
711 LG_memcpy(tmppal_lower, ppall, 32 * 3);
712 LG_memset(ppall, 0, 32 * 3);
713 gr_set_pal(0, 256, ppall);
714
715 gr_init_blend(1); // we want 2 tables, really, basically, and all
716
717 LG_memcpy(ppall, tmppal_lower, 32 * 3);
718 gr_set_pal(0, 256, ppall);
719 }
720 }
721
722 // fclose(ipalHdl); // reclaim the memory, fight the power
723 grd_ipal = NULL; // hack hack hack
724
725 // Spew(DSRC_EDITOR_Screen, ("Loaded the palette...\n"));
726 return (OK);
727 }
728
shock_alloc_ipal()729 void shock_alloc_ipal() {
730
731 // CC: Make sure we always allocate an ipal first
732 gr_alloc_ipal();
733
734 FILE *temp = fopen_caseless("res/data/ipal.dat", "rb");
735 if (temp == NULL) {
736 ERROR("Failed to open ipal.dat");
737 return;
738 }
739 fread(grd_ipal, 1, 32768, temp);
740 return;
741 // return(temp);
742 }
743
init_gamesys()744 errtype init_gamesys() {
745 extern void game_sched_init(void);
746
747 // Load data for weapons, drugs, wares
748 drugs_init();
749 init_all_side_icons();
750 // KLC wares_init(); doesn't do anything. leave it out.
751 game_sched_init();
752
753 return (OK);
754 }
755
free_gamesys(void)756 errtype free_gamesys(void) {
757 extern void game_sched_free(void);
758 game_sched_free();
759
760 return (OK);
761 }
762
763 // Okay, this should all move to somewhere more real, but I really
764 // can't put it in the right place until the new 3d regime comes into
765 // being
766
767 #define MAX_CUSTOMS 30
768
init_3d_objects()769 errtype init_3d_objects() {
770 vx_init(16);
771 return (OK);
772 }
773
obj_3d_shutdown()774 errtype obj_3d_shutdown() {
775 vx_close();
776 return (OK);
777 }
778
init_load_resources()779 errtype init_load_resources() {
780 // Open the screen resource stuff
781 if (ResOpenFile("res/data/gamescr.res") < 0)
782 critical_error(CRITERR_RES | 1);
783
784 // Open the appropriate mfd art file
785 if ((mfdart_res_file = ResOpenFile("res/data/mfdart.res")) < 0)
786 critical_error(CRITERR_RES | 2);
787
788 // Open the 3d objects
789 if (ResOpenFile("res/data/obj3d.res") < 0)
790 critical_error(CRITERR_RES | 9);
791
792 // Open the Citadel materials file
793 if (ResOpenFile("res/data/citmat.res") < 0)
794 critical_error(CRITERR_RES | 9);
795
796 // Open the Digital sound FX file
797 if (ResOpenFile("res/data/digifx.res") < 0)
798 critical_error(CRITERR_RES | 9);
799
800 // Go load the additional mod files
801 LoadModFiles();
802
803 return (OK);
804 }
805
806 #ifdef DUMMY // later
807
init_debug()808 errtype init_debug() {
809 errtype retval = OK;
810 return (retval);
811 }
812
init_editor_gadgets()813 errtype init_editor_gadgets() { return (OK); }
814
free_all(void)815 void free_all(void) {
816 extern void shutdown_config(void);
817 extern uchar cit_success;
818 extern void map_free(void);
819 extern void music_free(void);
820 extern void free_dpaths(void);
821 extern view360_shutdown(void);
822
823 _MARK_("free_all");
824
825 Spew(DSRC_TESTING_Test6, ("shutdown - 1\n"));
826 tm_close();
827 tm_remove_process(global_timer_id);
828 Spew(DSRC_TESTING_Test6, ("shutdown - 2\n"));
829 game_fr_shutdown();
830 cutscene_free();
831 map_free();
832 music_free();
833 Spew(DSRC_TESTING_Test6, ("shutdown - 3\n"));
834 player_shutdown();
835 Spew(DSRC_TESTING_Test6, ("shutdown - 4\n"));
836 if (cit_success)
837 free_dynamic_memory(DYNMEM_ALL);
838 Spew(DSRC_TESTING_Test6, ("shutdown - 5\n"));
839 mlimbs_shutdown(); // should shutdown music here too...?
840
841 snd_shutdown();
842 Spew(DSRC_TESTING_Test6, ("shutdown - 6\n"));
843 obj_3d_shutdown();
844 Spew(DSRC_TESTING_Test6, ("shutdown - 7\n"));
845 object_data_flush();
846 Spew(DSRC_TESTING_Test6, ("shutdown - 8\n"));
847 fr_shutdown();
848 Spew(DSRC_TESTING_Test6, ("shutdown - 9\n"));
849 screen_shutdown();
850 view360_shutdown();
851 status_vitals_end();
852 Spew(DSRC_TESTING_Test6, ("shutdown - 10\n"));
853 shutdown_input();
854 Spew(DSRC_TESTING_Test6, ("shutdown - 11\n"));
855 palette_shutdown();
856 // free_dpaths();
857 Spew(DSRC_TESTING_Test6, ("shutdown - 12\n"));
858 shutdown_config();
859 Spew(DSRC_TESTING_Test6, ("shutdown - 13\n"));
860
861 Spew(DSRC_TESTING_Test6, ("shutdown - final\n"));
862
863 _MARK_("free_all done");
864 }
865
866 #endif // DUMMY
867
868 // when you need those arms around you, you wont find my arms around you
869 // im going im going im going im gone
byebyemessage(void)870 void byebyemessage(void) {
871 extern uchar cit_success;
872 if (cit_success)
873 #ifdef DEMO
874 printf("Thanks for playing the System Shock CD Demo %s.\n", SYSTEM_SHOCK_VERSION);
875 #else
876 printf("Thanks for playing System Shock %s.\n", SHOCKOLATE_VERSION);
877 #endif
878 else
879 printf("Our system has been shocked!!!\b But remember to Salt The Fries\n");
880 }
881