/************************************ main.c *************************/ #include "sdi.h" #include "sdi_color.h" /* * Original copyright 1987 by Mark Weiser. * Modifications copyright 1991 by Xerox, Corp. * Permission to reproduce and use in any manner whatsoever on Suns is granted * so long as this copyright and other identifying marks of authorship * in the code and the game remain intact and visible. */ /* * A big, long, initialization routine. */ static short icon_image[] = { #include "city_icon1.h" }; mpr_static_static(Icon_pixrect, 64, 64, 1, icon_image); static void done_proc(); extern void main_event_proc(), canvas_resize_proc(); extern Notify_value canvas_input_proc(), asynch_event_proc(), synch_event_proc(); Notify_value scheduler(), input_notify(); #define FONT_NAME "-*-lucida-medium-r-normal-sans-12-*-*-*-*-*-*-*" static char tenblanks[] = " "; Panel launchpanel; my_error_proc(); /* * In need of no comment: */ main(argc, argv) int argc; char **argv; { extern char *version; Menu null_menu_gen(); char tmp_string[128]; struct timeval tp; char *s; /* randomize us */ gettimeofday(&tp, 0); srandom(tp.tv_sec); /* init score file from environment, if possible */ if ((s = (char *)getenv("SDI_SCORES")) != NULL) scorefile = s; sprintf(tmp_string, " SDI Control Panel%s%s%s%s%sby mark weiser", tenblanks,tenblanks,tenblanks,tenblanks,tenblanks); s = (char *)get_name(); if (s && s[0] != '\0') strcpy(user_name, s); xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, /* XV_ERROR_PROC, my_error_proc, */ NULL); /* make the control window, which serves as the base for all others. */ controlframe = xv_create(NULL, FRAME, XV_LABEL, tmp_string, FRAME_ICON, icon_create(ICON_IMAGE, &Icon_pixrect, 0), WIN_ERROR_MSG, "Can't create window.", WIN_X, 0, WIN_Y, 0, /* start at zero, move later. */ 0); init_colors(); font = (Xv_Font) xv_find(controlframe, FONT, FONT_FAMILY, FONT_FAMILY_DEFAULT, NULL); xv_set(controlframe, XV_FONT, font, NULL); process_args(argc, argv); init_circles(); init_city_bits(NULL); init_icons(); build_playing_fields(); controlpanel = xv_create(controlframe, PANEL, XV_FONT, font, WIN_ERROR_MSG, "Can't create window.", XV_WIDTH, 550, 0); if (use_color) xv_set(controlpanel, WIN_CMS, sdi_panel_colormap, NULL); init_control(controlpanel); window_fit(controlpanel); window_fit(controlframe); max_x = (int)xv_get(citypw, XV_WIDTH); max_y = (int)xv_get(citypw, XV_HEIGHT); { /* little block for a bunch of little variables */ int playwidth = (int)xv_get(cityframe, XV_WIDTH); int controlwidth = (int)xv_get(controlframe, XV_WIDTH); int controlheight = (int)xv_get(controlframe, XV_HEIGHT); int center; #define CONTROL_FRAME_TOP 200 #ifdef I_KNEW_HOW_TO_DO_THIS_IN_X center = screen.scr_rect.r_width/2; #else center = 600; #endif /* put the playing frames into position (control is at 0,0) */ xv_set(cityframe, XV_SHOW, TRUE, WIN_X, center - playwidth, WIN_Y, controlheight+CONTROL_FRAME_TOP, NULL); xv_set(launchframe, XV_SHOW, TRUE, WIN_X, center, WIN_Y, controlheight+CONTROL_FRAME_TOP, NULL); /* center the control frame */ xv_set(controlframe, XV_SHOW, TRUE, WIN_X, center - controlwidth/2, WIN_Y, CONTROL_FRAME_TOP, NULL); draw_background(); } /* end of little block */ init_cursor(); update_cursor(); do_with_delay(new_game_proc, 2, 0); window_main_loop(controlframe); exit(0); } static void done_proc(frame) Frame frame; { frame = frame; /* do nothing in a way that saber likes */ } build_playing_fields() { Xv_Cursor cursor; Panel citypanel; extern Panel_item foe_ground_item; cityframe = xv_create(controlframe, FRAME, XV_LABEL, " SDI Friend Cities", FRAME_SHOW_LABEL, TRUE, FRAME_DONE_PROC, done_proc, WIN_ERROR_MSG, "Can't create window.", XV_FONT, font, 0); citypanel = xv_create(cityframe, PANEL, 0); ballistic_item = xv_create(citypanel, PANEL_GAUGE, ATTR_LIST, panel_common, PANEL_LABEL_STRING, "Incoming missiles: ", 0); window_fit(citypanel); citycanvas = xv_create(cityframe, CANVAS, XV_X, 0, XV_WIDTH, max_x+(2*FIELD_MARGIN), XV_HEIGHT, max_y+(2*FIELD_MARGIN), WIN_ERROR_MSG, "Can't create window.", WIN_BELOW, citypanel, 0); citypw = canvas_paint_window(xv_create(citycanvas, CANVAS, XV_X, FIELD_MARGIN, XV_Y, FIELD_MARGIN, XV_WIDTH, max_x, XV_HEIGHT, max_y, CANVAS_RESIZE_PROC, canvas_resize_proc, CANVAS_RETAINED, TRUE, WIN_ERROR_MSG, "Can't create window.", NULL)); if (use_color) xv_set(citypw, WIN_CMS, sdi_colormap, NULL); xv_set(citypw, WIN_CONSUME_EVENTS, WIN_UP_EVENTS, NULL, WIN_EVENT_PROC, main_event_proc, NULL); window_fit(cityframe); init_cities(); launchframe = xv_create(controlframe, FRAME, XV_LABEL, " SDI Foe Launch", FRAME_SHOW_LABEL, TRUE, FRAME_DONE_PROC, done_proc, WIN_ERROR_MSG, "Can't create window.", XV_FONT, font, 0); launchpanel = xv_create(launchframe, PANEL, 0); foe_ground_item = xv_create(launchpanel, PANEL_GAUGE, ATTR_LIST, panel_common, PANEL_LABEL_STRING, "Missiles on the ground:", 0); window_fit(launchpanel); launchcanvas = xv_create(launchframe, CANVAS, XV_X, 0, XV_WIDTH, max_x+(2*FIELD_MARGIN), XV_HEIGHT, max_y+(2*FIELD_MARGIN), WIN_ERROR_MSG, "Can't create window.", 0); launchpw = canvas_paint_window(xv_create(launchcanvas, CANVAS, XV_X, FIELD_MARGIN, XV_Y, FIELD_MARGIN, XV_WIDTH, max_x, XV_HEIGHT, max_y, CANVAS_RESIZE_PROC, canvas_resize_proc, CANVAS_RETAINED, TRUE, WIN_ERROR_MSG, "Can't create window.", NULL)); if (use_color) xv_set(launchpw, WIN_CMS, sdi_colormap, NULL); xv_set(launchpw, WIN_CONSUME_EVENTS, WIN_UP_EVENTS, NULL, WIN_EVENT_PROC, main_event_proc, NULL); xv_set(launchcanvas, XV_HEIGHT, xv_get(launchcanvas, XV_HEIGHT), WIN_Y, 0, 0); xv_set(launchpanel, WIN_BELOW, launchcanvas, 0); window_fit(launchframe); } my_error_proc(object, avlist) Xv_object object; Attr_avlist avlist; { printf("%s\n", xv_error_format(object, avlist)); fflush(stdout); abort(); } #if 1 _exit(code) int code; { printf("normal end, code %d, sdi forcing memory dump anyway.\n", code); fflush(stdout); abort(); } #endif