home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char sccsid[] = "@(#)special_xv.c 1.2 92/05/28 SMI" ;
- /* from special.c 1.5 90/07/23 SMI */
- #endif
-
- /*
- * Copyright (c) 1986 by Sun Microsystems, Inc.
- */
-
- /*
- * this file contains stuff that varies between fighter, robot etc.
- *
- * It contains these routines:
- *
- * init_game_special(&argc,argv)
- * initialize all window system stuff etc. Called once at startup.
- *
- * init_communications()
- * sign on to the game. Called once at startup.
- *
- * dstar_main_loop()
- * Start the game, calls window_main_loop(). Called once at startup.
- *
- * terminate_game()
- * called from sigint handler (not interrupt time) to shut down.
- *
- * special_welcome()
- * set id & team from data sent by daemon
- *
- * normal_action()
- * called from time function, once per slice
- *
- * blast_action()
- * called from time function, once per time slice while dead
- *
- * set_blast_state()
- * called from time function, once per state change while dead
- *
- * special_add_player(object)
- * called when a new object joins the game
- *
- * special_remove_player(object)
- * called when an object leaves the game
- *
- * special_got_blasted(object)
- * called got shot (by player "object")
- *
- * special_new_status(object)
- * called when an object changes status
- */
-
-
-
- #include <fcntl.h>
- #include <stdio.h>
- #include <xview/window_hs.h>
- #include <X11/Xlib.h>
- #include <X11/Xatom.h>
- #include <xview/xview.h>
- #include <xview/canvas.h>
- #include <xview/cursor.h>
- #include <xview/cms.h>
- #include <math.h>
- #include <sys/time.h>
- #include "graphics.h"
- #include "dstar.h"
-
- static Server_image Main_Image, Main_sleep_Image, Main_no_Image ;
- static Server_image current_image ;
-
- Frame Main_Frame ;
- Canvas Main_Canvas ;
- Icon Main_Icon ;
- Cursor Main_Cursor ;
- Cursor Default_Cursor ;
-
- Xgl_X_window Main_x_win, Control_x_win, xgl_x_win;
- Atom catom;
- Window frame_window;
- Window Main_canvas_window, Control_canvas_window,
- canvas_window;
- Display *display;
- Xv_Window Main_pw;
-
-
- static struct timeval First_Time ;
- static int nframes ;
-
- int status_display ;
-
- #ifdef XGL
- static Xgl_sys_st Main_state ;
- static Xgl_cmap cmap1, cmap2 ;
- static Xgl_color_list ctable ;
- static Xgl_color ctab1[64], ctab2[64] ;
- static Xgl_win_ras Main_ras, Control_ras ;
- Xgl_mem_ras Cursor_ras;
- Xgl_3d_ctx Main_gfx, Control_gfx ;
- Xgl_2d_ctx Text_gfx;
- static Xgl_bounds_f3d Idwin = {-1.,1.,-1.,1.,-1.,1.} ;
- static Xgl_bounds_f2d Ctrldcvp = {0.,500.,600.,740.} ;
- static Xgl_bounds_f3d Ctrlwin = {0.0,2.0,0.0,5.0,0.,1.} ;
- static Xgl_bounds_f2d Textdcvp = {200.,740.,600.,740.} ;
- static Xgl_bounds_f2d Textwin = {-0.5,1.5,0.0,5.0} ;
- static int dbuffer = 0 ;
-
- #define Dev_gp1_dbuf_putcolormap(ctx,start,len,r,g,b) \
- dbuf_putcolormap(start,len,r,g,b)
- #else
- GP1_handle Main_gfx, Control_gfx ;
- #endif XGL
-
- static unsigned char red[] = { 0, 255, 192, 128, 255, 0, 0, 255 } ;
- static unsigned char green[] = { 0, 255, 192, 128, 0, 255, 0, 255 } ;
- static unsigned char blue[] = { 64, 255, 192, 128, 0, 0, 255, 0 } ;
-
- static short dstar_icon[] = {
- #include "dstar.icon"
- } ;
-
- static short dstar_sleep_icon[] = {
- #include "dstar_sleep.icon"
- } ;
-
- static short nodstar_icon[] = {
- #include "nodstar.icon"
- } ;
-
- static short dstar_cursor[] = {
- #include "cursor2.pr"
- } ;
-
-
- static void open_graphics() ;
- static void Canvas_Proc() ;
- static void Canvas_Resize_Proc(), Fake_Resize_Proc() ;
- static void Control_Proc() ;
- static void Control_Repaint_Proc() ;
- static void Control_Resize_Proc() ;
- static Notify_value Destroy_func(), Close_func() ;
- void timefunc(), sleepfunc() ;
- static int sigint() ;
- extern Notify_value dstar_prioritizer() ;
-
-
- #define MAX_FIGHTERS 2
-
- static int fighters[MAX_FIGHTERS] ;
-
-
-
- static char *help_info ="\
- -k n kill flag, 1=robots, 2=humans, 3=both\n\
- -t n time interval for above\n\
- -free free-for-all\n\
- -teams players divided into two teams\n\
- -help this list\n\
- hostname used to slave one local net to another" ;
-
- static need_resize = FALSE;
- Xv_window resize_win;
- int resize_width, resize_height;
-
-
-
-
-
-
-
-
- init_game_special(argc,argv)
- int argc ;
- char **argv ;
- {
- int i,j,k,iret ;
- int c ;
- Pt3d p1, p2, p3, p4 ;
- char *mastername = NULL ;
- unsigned char r[256], g[256], b[256] ;
- static Xv_singlecolor cursor_color = {255,255,0} ;
- unsigned char *mem;
- Xgl_color rop_color, space_color, text_color;
- int panel_flag = 0 ;
- extern fptr fighter_vector[VECTOR_LENGTH] ;
- Server_image svr_image ;
-
-
- xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv,NULL);
-
- Main_Image = (Server_image)xv_create(NULL, SERVER_IMAGE,
- XV_WIDTH, 64,
- XV_HEIGHT, 64,
- SERVER_IMAGE_BITS, dstar_icon,
- NULL);
-
- Main_sleep_Image = (Server_image)xv_create(NULL, SERVER_IMAGE,
- XV_WIDTH, 64,
- XV_HEIGHT, 64,
- SERVER_IMAGE_BITS, dstar_sleep_icon,
- NULL);
-
- Main_no_Image = (Server_image)xv_create(NULL, SERVER_IMAGE,
- XV_WIDTH, 64,
- XV_HEIGHT, 64,
- SERVER_IMAGE_BITS, nodstar_icon,
- NULL);
-
- Main_Icon = (Icon)xv_create(XV_NULL, ICON,
- ICON_IMAGE, Main_no_Image,
- XV_X, 100,
- XV_Y, 100,
- NULL);
-
- svr_image = (Server_image)xv_create(XV_NULL, SERVER_IMAGE,
- XV_WIDTH, 16,
- XV_HEIGHT, 16,
- SERVER_IMAGE_BITS, dstar_cursor,
- NULL);
-
- Main_Cursor = (Xv_Cursor)xv_create(XV_NULL, CURSOR,
- CURSOR_IMAGE, svr_image,
- CURSOR_XHOT, 8, CURSOR_YHOT, 8,
- CURSOR_FOREGROUND_COLOR, cursor_color,
- NULL);
-
- Main_Frame = window_create(NULL, FRAME,
- FRAME_ICON, Main_Icon,
- FRAME_LABEL, "Dstar - experimental",
- FRAME_ARGC_PTR_ARGV, &argc, argv,
- 0 ) ;
- if(Main_Frame == NULL)
- exit(1) ;
-
- current_image = Main_no_Image ;
-
- Main_Canvas = window_create(Main_Frame, CANVAS,
- WIN_WIDTH, 1000,
- WIN_HEIGHT, 750,
- OPENWIN_AUTO_CLEAR, FALSE,
- CANVAS_RESIZE_PROC, Fake_Resize_Proc,
- CANVAS_RETAINED, FALSE,
- CANVAS_FIXED_IMAGE, FALSE,
- NULL);
- if(Main_Canvas == NULL)
- exit(1) ;
- Main_pw = (Xv_Window) canvas_paint_window(Main_Canvas);
- xv_set(Main_pw,
- WIN_EVENT_PROC, Canvas_Proc,
- WIN_CONSUME_EVENTS, WIN_MOUSE_BUTTONS,
- LOC_MOVE,
- LOC_DRAG,
- WIN_IN_TRANSIT_EVENTS,
- WIN_ASCII_EVENTS,
- WIN_LEFT_KEYS,
- WIN_RIGHT_KEYS,
- WIN_TOP_KEYS,
- NULL,
- 0 ) ;
-
- Default_Cursor = (Cursor) window_get(Main_pw, WIN_CURSOR) ;
-
- window_fit(Main_Frame);
-
- #ifdef XGL
- Main_state = xgl_open(XGL_SYS_ST_ERROR_DETECTION, TRUE, 0 ) ;
- if(Main_state == NULL)
- exit(1) ;
-
- /* compute d.b. colormaps */
-
- for(i=0; i<8; ++i)
- for(j=0; j<8; ++j)
- {
- ctab1[i+8*j].rgb.r = (float)red[j]/256. ;
- ctab1[i+8*j].rgb.g = (float)green[j]/256. ;
- ctab1[i+8*j].rgb.b = (float)blue[j]/256. ;
- ctab2[8*i+j].rgb.r = (float)red[j]/256. ;
- ctab2[8*i+j].rgb.g = (float)green[j]/256. ;
- ctab2[8*i+j].rgb.b = (float)blue[j]/256. ;
- }
- for(i=0; i<8; ++i)
- dbmap[i] = (i << 3) | i ;
-
- ctable.start_index = 0 ;
- ctable.length = 64 ;
- ctable.colors = ctab1 ;
- cmap1 = xgl_color_map_create(
- XGL_CMAP_COLOR_TABLE_SIZE, 64,
- XGL_CMAP_COLOR_TABLE, &ctable, 0) ;
- if(cmap1 == NULL)
- exit(1) ;
- ctable.colors = ctab2 ;
- cmap2 = xgl_color_map_create(
- XGL_CMAP_COLOR_TABLE_SIZE, 64,
- XGL_CMAP_COLOR_TABLE, &ctable, 0) ;
- if(cmap2 == NULL)
- exit(1) ;
-
- display = (Display *) xv_get(Main_Frame, XV_DISPLAY);
-
- Main_canvas_window = (Window) xv_get(Main_pw, XV_XID);
- frame_window = (Window) xv_get(Main_Frame, XV_XID);
-
- catom = XInternAtom(display, "WM_COLORMAP_WINDOWS", False);
- XChangeProperty(display, frame_window, catom, XA_WINDOW, 32,
- PropModeAppend, &Main_canvas_window, 1);
-
- Main_x_win.X_display = (void *) display;
- Main_x_win.X_window = (Xgl_usgn32) Main_canvas_window;
- Main_x_win.X_screen = (int) DefaultScreen(display);
-
- Main_ras = xgl_window_raster_device_create(
- XGL_WIN_X, &Main_x_win,
- XGL_RAS_COLOR_MAP, cmap1,
- XGL_RAS_COLOR_TYPE, XGL_COLOR_INDEX,
- 0 ) ;
- if(Main_ras == NULL)
- exit(1) ;
-
- Cursor_ras = xgl_memory_raster_device_create(
- XGL_RAS_DEPTH, 1,
- XGL_RAS_WIDTH, 16,
- XGL_RAS_HEIGHT, 16,
- 0);
- xgl_object_get(Cursor_ras, XGL_MEM_RAS_MEMORY_ADDRESS, &mem);
- for (i = 0; i < 16; i++) {
- mem[i * 2] = dstar_cursor[i] >> 8;
- mem[i * 2 + 1] = dstar_cursor[i];
- }
-
-
- WIN_MAT = xgl_transform_create(0) ;
- OBJ_MAT = xgl_transform_create(0) ;
- ROT_MAT = xgl_transform_create(0) ;
- TM1 = xgl_transform_create(0) ;
- TM2 = xgl_transform_create(0) ;
- TM3 = xgl_transform_create(0) ;
- Ctrl_view_mat = xgl_transform_create(0) ;
- PERSP_MAT = xgl_transform_create(0) ;
- ID_MAT = xgl_transform_create(0) ;
- xgl_transform_identity(ID_MAT) ;
-
- space_color.index = dbmap[0];
- rop_color.index = dbmap[YELLOW];
- Main_gfx = xgl_3d_context_create(
- XGL_CTX_DEFERRAL_MODE, XGL_DEFER_ASAP,
- XGL_CTX_DEVICE, Main_ras,
- XGL_CTX_NEW_FRAME_ACTION, XGL_CTX_NEW_FRAME_VRETRACE|
- XGL_CTX_NEW_FRAME_CLEAR,
- XGL_CTX_PICK_ENABLE, FALSE,
- XGL_CTX_VDC_MAP, XGL_VDC_MAP_ALL,
- XGL_CTX_VDC_WINDOW, &Idwin,
- XGL_CTX_VDC_ORIENTATION, XGL_Y_UP_Z_TOWARD,
- XGL_CTX_GLOBAL_MODEL_TRANS, WIN_MAT,
- XGL_CTX_SURF_FRONT_COLOR, &rop_color,
- XGL_3D_CTX_SURF_FACE_DISTINGUISH, 0,
- XGL_3D_CTX_SURF_FRONT_ILLUMINATION, XGL_ILLUM_NONE,
- XGL_3D_CTX_SURF_BACK_ILLUMINATION, XGL_ILLUM_NONE,
- XGL_3D_CTX_SURF_FACE_CULL, XGL_CULL_OFF,
- XGL_3D_CTX_VIEW_CLIP_PLUS_W_ONLY, FALSE,
- 0 ) ;
-
- Control_gfx = xgl_3d_context_create(
- XGL_CTX_DEFERRAL_MODE, XGL_DEFER_ASAP,
- XGL_CTX_DEVICE, Main_ras,
- XGL_CTX_PICK_ENABLE, FALSE,
- XGL_CTX_VDC_MAP, XGL_VDC_MAP_ALL,
- XGL_CTX_VDC_WINDOW, &Ctrlwin,
- XGL_CTX_VDC_ORIENTATION, XGL_Y_UP_Z_TOWARD,
- XGL_CTX_VIEW_TRANS, Ctrl_view_mat,
- XGL_3D_CTX_SURF_FACE_DISTINGUISH, 0,
- XGL_3D_CTX_SURF_FRONT_ILLUMINATION, XGL_ILLUM_NONE,
- XGL_3D_CTX_SURF_BACK_ILLUMINATION, XGL_ILLUM_NONE,
- XGL_3D_CTX_SURF_FACE_CULL, XGL_CULL_OFF,
- XGL_3D_CTX_VIEW_CLIP_PLUS_W_ONLY, FALSE,
- 0 ) ;
- text_color.index = dbmap[RED];
- Text_gfx = xgl_2d_context_create(
- XGL_CTX_DEFERRAL_MODE, XGL_DEFER_ASAP,
- XGL_CTX_DEVICE, Main_ras,
- XGL_CTX_VDC_MAP, XGL_VDC_MAP_ALL,
- XGL_CTX_VDC_WINDOW, &Textwin,
- XGL_CTX_VDC_ORIENTATION, XGL_Y_UP_Z_TOWARD,
- XGL_CTX_LINE_COLOR, &text_color,
- XGL_CTX_SFONT_TEXT_COLOR, &text_color,
- XGL_CTX_SFONT_CHAR_HEIGHT, 0.05,
- XGL_CTX_SFONT_CHAR_EXPANSION_FACTOR, 0.35,
- XGL_CTX_SFONT_TEXT_ALIGN_HORIZ, XGL_TEXT_ALIGN_HORIZ_LEFT,
- XGL_CTX_SFONT_TEXT_ALIGN_VERT, XGL_TEXT_ALIGN_VERT_HALF,
- 0 ) ;
-
-
- #else
- Main_gfx = Dev_gp1_create(Main_pw, 3, &iret) ;
- if(!Main_gfx) {
- printf("can't open gp, err=%d\n",iret) ;
- exit(1) ;
- }
- Dev_gp1_reset_to_defaults(Main_gfx) ;
-
- hwdb = pw_dbl_get(Main_pw, PW_DBL_AVAIL) ;
- hwdb = 0 ;
- printf("hwdb=%d\n",hwdb) ;
- #endif XGL
-
-
- status_display = 0 ;
-
- while(--argc > 0)
- {
- ++argv ;
- if(strcmp(*argv,"-free")==0)
- game_type = GAME_FREE ;
-
- else if(strcmp(*argv,"-teams")==0)
- game_type = GAME_TEAMS ;
-
- else if(strcmp(*argv,"-help")==0)
- {
- printf(help_info) ;
- exit(0) ;
- }
-
- else if(strcmp(*argv,"-ctdb")==0)
- hwdb = 0 ;
-
- else if(strcmp(*argv,"-panel")==0)
- panel_flag = 1 ;
-
- else if(strcmp(*argv,"-status")==0)
- status_display = 1 ;
-
- else if(strcmp(*argv,"-debug")==0)
- debug_level = 1 ;
-
- else if(**argv == '-')
- printf("unknown option %s, '-help' for more info\n",*argv) ;
-
- else
- mastername = *argv ;
- }
-
- #ifdef DEBUG
- if(panel_flag)
- {
- init_panel(Main_Frame) ;
- window_fit_height(Main_Frame) ;
- }
- #endif DEBUG
-
-
- #ifndef XGL
- if(!hwdb)
- {
- Dev_gp1_set_dbuf(Main_gfx, 3, "dstar") ;
- Dev_gp1_dbuf_putcolormap(Main_gfx, 0, 8, red, green, blue) ;
- Dev_gp1_dbuf_control(Main_gfx, 3) ;
- Dev_gp1_dbuf_write_mask(Main_gfx, 7) ;
- Dev_gp1_dbuf_color(Main_gfx,4) ;
- }
- else
- {
- pw_dbl_access(Main_pw) ;
- pw_dbl_set(Main_pw, PW_DBL_WRITE, PW_DBL_BOTH, 0) ;
- hwdb = 1 ;
- Dev_gp1_set_sbuf(Main_gfx, 3, "dstar") ;
- Dev_gp1_set_write_mask(Main_gfx, 7) ;
- Dev_gp1_set_color(Main_gfx,4) ;
- }
-
- Dev_gp1_getcmsname(Main_gfx, cmsname) ;
- pw_setcmsname(Control_pw, cmsname) ;
- pw_putcolormap(Control_pw, 0,1, red,green,blue) ;
- #endif !XGL
-
-
- #ifdef XGL
- persp_window_mat(0.,1.,-1.,1.,-1.,1.,1.,10000.,P_matrix) ;
- #else
- Dev_gp1_persp_window_mat(0.,1.,-1.,1.,-1.,1.,1.,10000.,P_matrix) ;
- #endif XGL
-
-
- notify_interpose_destroy_func(Main_Frame, Destroy_func) ;
- notify_interpose_event_func(Main_Frame, Close_func, NOTIFY_SAFE) ;
-
- Me->id = -1 ;
- Me->team = 0 ;
- Me->score = 0 ;
- Me->class = OBJ_PLAYER ;
- Me->status = (int) window_get(Main_Frame, FRAME_CLOSED) ?
- OBJ_SLEEPING : OBJ_ACTIVE ;
- Me->flags = 0 ;
- Me->Posn.x = (random() % 3000) - 1500.0 ;
- Me->Posn.y = (random() % 3000) - 1500.0 ;
- Me->Posn.z = - 2000.0 ;
- Me->Forward.x = 0.0 ;
- Me->Forward.y = 0.0 ;
- Me->Forward.z = 1.0 ;
- Me->Up.x = 0.0 ;
- Me->Up.y = 1.0 ;
- Me->Up.z = 0.0 ;
- Me->Right.x = 1.0 ;
- Me->Right.y = 0.0 ;
- Me->Right.z = 0.0 ;
- Me->Delta.x = 0.0 ;
- Me->Delta.y = 0.0 ;
- Me->Delta.z = 0.0 ;
- Me->Pointing = Me->Forward ;
- Me->Speed = DEFAULT_SPEED ;
- Me->description = FIGHTER1_DESC ;
- bcopy(fighter_vector, Me->f_vector, sizeof(fighter_vector)) ;
-
- Left_But = 1 ;
- Middle_But = 0 ;
- Right_But = 0 ;
- Side_1 = Side_2 = Side_3 = Side_4 = Side_5 =
- Side_6 = Side_7 = Side_8 = Side_9 = Side_10 = 0 ;
-
- init_blasts(BLAST_DESC) ;
- init_fighter1(FIGHTER1_DESC) ;
- init_fighter2(FIGHTER2_DESC) ;
- init_planet(PLANET1_DESC) ;
- init_monolith(MONOLITH_DESC) ;
- init_missile(MISSILE_DESC) ;
- missile_init() ;
-
-
-
-
- fighters[0] = FIGHTER1_DESC ;
- fighters[1] = FIGHTER2_DESC ;
-
- for(i=0; i<MAX_OBJECTS; sort_list[i++] = 0) ;
- nobjects = 0 ;
-
- init_netio(getenv("USER"), mastername) ;
-
- First_Time.tv_sec = -1 ;
- nframes = 0 ;
-
- auto_pilot = 0 ;
- mouse_control = 0 ;
- }
-
-
- #ifdef DEBUG
- static
- report_rate()
- {
- char line[40] ;
- float dtime ;
- float rate ;
-
- if(First_Time.tv_sec == -1)
- First_Time = Now ;
- else
- {
- dtime = (Now.tv_sec - First_Time.tv_sec) +
- (Now.tv_usec - First_Time.tv_usec)*.000001 ;
-
- ++nframes ;
- if(nframes%10 == 0)
- {
- rate = nframes/dtime ;
- sprintf(line,"%7.2f %4d %8.3f",dtime,nframes,rate) ;
- window_set(Main_Frame, FRAME_LABEL, line, 0) ;
- }
- }
- }
- #endif DEBUG
-
-
-
- void
- dstar_main_loop()
- {
- window_main_loop(Main_Frame) ;
- }
-
-
-
- int
- terminate_game()
- {
- window_set(Main_Frame, FRAME_NO_CONFIRM, TRUE, 0);
- window_destroy(Main_Frame) ;
- }
-
-
-
- void
- special_welcome()
- {
- set_ship_description() ;
- }
-
-
-
- special_sleep_func()
- {
- int i, nawake = 0, nsleep = 0 ;
- register Object *obj = &objects[0] ;
- Server_image new_image ;
-
- for(i=0; i<MAX_OBJECTS; ++i)
- {
- if( obj->class == OBJ_PLAYER &&
- !(obj->flags & ROBOT_FLAG) &&
- obj != Me )
- {
- if( obj->status == OBJ_SLEEPING )
- ++nsleep ;
- else
- ++nawake ;
- }
- ++obj ;
- }
- if(nawake > 0)
- new_image = Main_Image ;
- else if(nsleep > 0)
- new_image = Main_sleep_Image ;
- else
- new_image = Main_no_Image ;
-
- if(new_image != current_image)
- {
- window_set(Main_Icon, ICON_IMAGE, new_image, 0 ) ;
- current_image = new_image ;
- }
- }
-
-
-
- void
- normal_action()
- {
- if (need_resize == TRUE) {
- Canvas_Resize_Proc(resize_win, resize_width, resize_height);
- need_resize = FALSE;
- }
- get_input() ;
- if(Me->flags & RADAR_FLAG)
- do_radar() ;
- else
- Me->target = NULL ;
- control_ship() ; /* read inputs, set position */
- control_enemies() ;
- #ifdef DEBUG
- report_rate() ;
- #endif
- draw_image() ;
- if(Me->flags & LASER_FLAG)
- test_objects() ;
-
-
- if( Me->id != -1 )
- {
- net_start_message( NULL ) ;
- send_status(Me) ; /* tell everyone where I am */
- fly_missiles() ;
- }
- }
-
-
-
- void
- blast_action()
- {
- register Object *me = Me ;
- control_object(me) ;
- #ifdef DEBUG
- report_rate() ;
- #endif
- draw_image() ;
-
- if( me->id != -1 )
- {
- net_start_message( NULL ) ;
- fly_missiles() ;
- }
- }
-
-
-
-
-
- /* this routine is called whenever the blast state changes */
-
-
- set_blast_state(state)
- Blast_State state ;
- {
- static char red0[] = {192} ;
- static char green0[] = { 0} ;
- static char blue0[] = { 0} ;
- static char red1[] = { 0} ;
- static char green1[] = { 0} ;
- static char blue1[] = { 64} ;
-
- switch(state)
- {
- case B_FLASH:
- Dev_gp1_dbuf_putcolormap(Main_gfx, 0, 1, red0, green0, blue0) ;
- break ;
-
- case B_WAIT:
- Dev_gp1_dbuf_putcolormap(Main_gfx, 0, 1, red1, green1, blue1) ;
- break ;
-
- case B_NIL:
- Me->status = OBJ_ACTIVE ;
- Me->Posn.x = (random() % 3000) - 1500.0 ;
- Me->Posn.y = (random() % 3000) - 1500.0 ;
- Me->Posn.z = (random() % 3000) - 1500.0 ;
- Me->Speed = DEFAULT_SPEED ;
- set_ship_description() ;
- net_start_message( NULL ) ;
- send_status(Me) ; /* tell everyone I'm back */
- break ;
- }
- }
-
-
-
- special_add_player(object)
- register Object *object ;
- {
- sort_list[nobjects++] = object->id ;
- }
-
-
-
-
- special_remove_player(object)
- register Object *object ;
- {
- register int i = 0 ;
- register int done = 0 ;
- register int j ;
- register int id = object->id ;
- int nobj = 0 ;
- register Object *obj = &objects[0] ;
-
- if(object != Me)
- while(!done)
- {
- if(sort_list[i] == id)
- {
- for(j=i+1; j<MAX_OBJECTS; sort_list[i++] = sort_list[j++]) ;
- --nobjects ;
- done = 1 ;
- }
- else if (++i >= nobjects)
- {
- fprintf(stderr,
- "internal error: object %d: %s not found in sort_list\n",
- object->id, object->name) ;
- done = 1 ;
- }
- }
- }
-
-
- special_got_blasted(object)
- Object *object ;
- {
- missiles_remaining = MISSILES_PER_LIFE ;
- }
-
-
-
-
- special_someone_got_blasted(object,victim)
- Object *object,*victim ;
- {}
-
-
-
-
- special_new_status(object)
- Object *object ;
- {}
-
-
-
-
- static
- set_ship_description()
- {
- Me->description = fighters[Me->team % MAX_FIGHTERS] ;
- }
-
-
-
-
- /****
- *
- * read control inputs, update ship's position/velocity/"up" vectors
- *
- ****/
-
-
- #ifdef XGL
- static
- get_input()
- {
- Xgl_bounds_f2d bounds ;
-
- xgl_object_get(Main_gfx, XGL_CTX_DC_VIEWPORT, &bounds) ;
-
- Mouse_ax = (float) Mouse_x / (bounds.xmax - bounds.xmin) ;
- Mouse_ay = 1.0 - (float) Mouse_y / (bounds.ymax - bounds.ymin) ;
- }
-
- #else
-
- static
- get_input()
- {
- Rect *rect, *Dev_gp1_rect() ;
-
- rect = Dev_gp1_rect(Main_gfx) ;
-
- Mouse_ax = (float) Mouse_x / rect->r_width ;
- Mouse_ay = 1.0 - (float) Mouse_y / rect->r_height ;
- }
- #endif XGL
-
-
-
-
-
-
- static void
- Canvas_Proc(window, event, arg)
- Window window ;
- Event *event ;
- caddr_t arg ;
- {
- Cursor new_cursor ;
-
- Mouse_x = event_x(event) ;
- Mouse_y = event_y(event) ;
-
- if (event_is_ascii(event) && event_is_up(event))
- return;
- #if FALSE
- printf("in Canvas_Proc: %d\n", event_id(event));
- #endif
- switch(event_id(event))
- {
- case 'A':
- auto_fire = !auto_pilot ;
- case 'a':
- if(auto_pilot)
- {
- auto_pilot = auto_fire = 0 ;
- }
- else
- {
- auto_pilot = 1 ;
- }
- save_auto_state();
- if(!mouse_control || auto_pilot)
- {
- new_cursor = Default_Cursor ;
- }
- else
- {
- new_cursor = Main_Cursor ;
- }
- window_set(Main_pw, WIN_CURSOR, new_cursor, 0) ;
- break ;
-
- case 'r':
- if (event_is_down(event)) {
- if( !((Me->flags ^= RADAR_FLAG) & RADAR_FLAG))
- Me->target = NULL ;
- }
- break ;
-
- case MS_LEFT:
- Left_But = event_is_down(event) ;
- if(Left_But)
- {
- mouse_control = !mouse_control ;
- if(!mouse_control)
- {
- restore_auto_state();
- new_cursor = Default_Cursor ;
- }
- else
- {
- if(auto_pilot)
- {
- save_auto_state();
- auto_pilot = auto_fire = 0;
- }
- new_cursor = Main_Cursor ;
- }
- window_set(Main_pw, WIN_CURSOR, new_cursor, 0) ;
- }
- break ;
-
- case MS_MIDDLE:
- Middle_But = event_is_down(event) ;
- break ;
-
- case MS_RIGHT:
- Right_But = event_is_down(event) ;
- break ;
-
- #if FALSE
- case KEY_TOP(1):
- #endif
- case KEY_TOP(2):
- if(event_is_down(event))
- missile_arm() ;
- break ;
-
- #if FALSE
- case KEY_TOP(2):
- #endif
- case KEY_TOP(3):
- if(event_is_down(event))
- missile_launch(NULL) ;
- break ;
-
- case KEY_LEFT(1):
- case KEY_RIGHT(1):
- Side_1 = event_is_down(event) ;
- break ;
-
- case KEY_LEFT(2):
- case KEY_RIGHT(2):
- Side_2 = event_is_down(event) ;
- break ;
-
- case KEY_LEFT(3):
- case KEY_RIGHT(4):
- Side_3 = event_is_down(event) ;
- break ;
-
- case KEY_LEFT(4):
- case KEY_RIGHT(5):
- Side_4 = event_is_down(event) ;
- break ;
-
- case KEY_LEFT(6):
- case KEY_RIGHT(8):
- Side_6 = event_is_down(event) ;
- break ;
-
- case KEY_LEFT(5):
- case KEY_LEFT(7):
- win_post_event(Main_Frame, event, NOTIFY_SAFE) ;
- break ;
-
- case KEY_LEFT(8):
- case KEY_RIGHT(11):
- Side_8 = event_is_down(event) ;
- break ;
-
- case KEY_LEFT(9):
- case KEY_RIGHT(13):
- Side_9 = event_is_down(event) ;
- break ;
-
- case KEY_LEFT(10):
- case KEY_RIGHT(14):
- Side_10 = event_is_down(event) ;
- break ;
-
- case LOC_WINEXIT:
- #ifdef COMMENT
- Left_But = 0 ;
- Middle_But = 0 ;
- Right_But = 0 ;
- Side_1 = Side_2 = Side_3 = Side_4 = Side_5 =
- Side_6 = Side_7 = Side_8 = Side_9 = Side_10 = 0 ;
- #endif COMMENT
-
- case LOC_WINENTER:
- #if FALSE
- case LOC_RGNENTER:
- Left_But = (int) window_get(window, WIN_EVENT_STATE, MS_LEFT) ;
- Middle_But = (int) window_get(window, WIN_EVENT_STATE, MS_MIDDLE) ;
- Right_But = (int) window_get(window, WIN_EVENT_STATE, MS_RIGHT) ;
- Side_1 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(1)) ;
- Side_2 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(2)) ;
- Side_3 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(3)) ;
- Side_4 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(4)) ;
- Side_5 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(5)) ;
- Side_6 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(6)) ;
- Side_7 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(7)) ;
- Side_8 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(8)) ;
- Side_9 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(9)) ;
- Side_10 = (int) window_get(window, WIN_EVENT_STATE, KEY_LEFT(10)) ;
- #endif
- break ;
- }
- }
-
- static void
- Fake_Resize_Proc(canvas, width, height)
- Canvas canvas ;
- int width, height ;
- {
- resize_win = canvas;
- resize_width = width;
- resize_height = height;
- need_resize = TRUE;
- }
-
- static void
- Canvas_Resize_Proc(canvas, width, height)
- Canvas canvas ;
- int width, height ;
- {
- Xgl_bounds_f2d new_ctrldcvp ;
- Xgl_bounds_f2d new_textdcvp ;
-
- if (!Main_Canvas)
- return;
- if (Main_ras) {
- xgl_window_raster_resize(Main_ras);
- }
- #if FALSE
- if (!Control_gfx || !Text_gfx)
- return;
- xgl_object_get(Control_gfx, XGL_CTX_DC_VIEWPORT, &new_ctrldcvp);
- xgl_object_get(Text_gfx, XGL_CTX_DC_VIEWPORT, &new_textdcvp);
- #if FALSE
- fprintf(stderr, "old ctrl: %f %f %f %f\n",
- new_ctrldcvp.xmin, new_ctrldcvp.xmax,
- new_ctrldcvp.ymin, new_ctrldcvp.ymax);
- fprintf(stderr, "old text: %f %f %f %f\n",
- new_textdcvp.xmin, new_textdcvp.xmax,
- new_textdcvp.ymin, new_textdcvp.ymax);
- #endif
- new_ctrldcvp.xmin = 0.02 * (float)width;
- new_ctrldcvp.xmax = 0.50 * (float)width;
- new_ctrldcvp.ymin = 0.80 * (float)height;
- new_ctrldcvp.ymax = 0.98 * (float)height;
- new_textdcvp.xmin = 0.20 * (float)width;
- new_textdcvp.xmax = 0.74 * (float)width;
- new_textdcvp.ymin = 0.80 * (float)height;
- new_textdcvp.ymax = 0.98 * (float)height;
- #if FALSE
- fprintf(stderr, "%d %d\n", width, height);
- fprintf(stderr, "%d %d\n", w, h);
- fprintf(stderr, "setting ctrl to: %f %f %f %f\n",
- new_ctrldcvp.xmin, new_ctrldcvp.xmax,
- new_ctrldcvp.ymin, new_ctrldcvp.ymax);
- fprintf(stderr, "setting text to: %f %f %f %f\n",
- new_textdcvp.xmin, new_textdcvp.xmax,
- new_textdcvp.ymin, new_textdcvp.ymax);
- #endif
-
- xgl_object_set(Control_gfx, XGL_CTX_DC_VIEWPORT, &new_ctrldcvp, 0);
- #if FALSE
- fprintf(stderr, "between 1st and 2nd resizes\n");
- fflush(stdout);
- #endif
- xgl_object_set(Text_gfx, XGL_CTX_DC_VIEWPORT, &new_textdcvp, 0);
- xgl_object_get(Control_gfx, XGL_CTX_DC_VIEWPORT, &new_ctrldcvp);
- xgl_object_get(Text_gfx, XGL_CTX_DC_VIEWPORT, &new_textdcvp);
- #if FALSE
- fprintf(stderr, "new ctrl: %f %f %f %f\n",
- new_ctrldcvp.xmin, new_ctrldcvp.xmax,
- new_ctrldcvp.ymin, new_ctrldcvp.ymax);
- fprintf(stderr, "new text: %f %f %f %f\n",
- new_textdcvp.xmin, new_textdcvp.xmax,
- new_textdcvp.ymin, new_textdcvp.ymax);
- #endif
- #endif
- }
-
-
-
- static void
- Control_Proc(window, event, arg)
- Window window ;
- Event *event ;
- caddr_t arg ;
- {
- }
-
-
-
- static void
- Control_Repaint_Proc(canvas, pixwin, repaint_area)
- Canvas canvas ;
- Pixwin *pixwin ;
- Rectlist *repaint_area ;
- {
- }
-
-
-
- static void
- Control_Resize_Proc(canvas, width, height)
- Canvas canvas ;
- int width, height ;
- {
- }
-
-
-
- static Notify_value
- Destroy_func(frame, status)
- Frame frame ;
- Destroy_status status ;
- {
- if(status != DESTROY_CHECKING)
- {
- (void) notify_set_itimer_func(&Main_Timer, timefunc,
- ITIMER_REAL, NULL, 0) ;
- if( Me->id != -1 )
- {
- net_remove_player(Me->id) ;
- net_flush() ;
- }
- }
-
- return(notify_next_destroy_func(frame, status)) ;
- }
-
-
-
- static Notify_value
- Close_func(frame, event, arg, type)
- Frame frame ;
- Event *event ;
- Notify_arg arg ;
- Notify_event_type type ;
- {
- int closed_initial, closed_current ;
- Notify_value value ;
-
- closed_initial = (int) window_get(frame, FRAME_CLOSED) ;
-
- value = notify_next_event_func(frame, event, arg, type) ;
-
- closed_current = (int) window_get(frame, FRAME_CLOSED) ;
-
- if(closed_initial != closed_current)
- if(closed_current)
- {
- Me->status = OBJ_SLEEPING ;
- (void) notify_set_itimer_func(&Main_Timer, sleepfunc,
- ITIMER_REAL, &Sleep_Timer, 0) ;
- if( Me->id != -1 )
- {
- net_start_message( NULL ) ;
- send_status(Me) ; /* tell everyone where I am */
- }
- }
- else
- {
- Me->status = OBJ_ACTIVE ;
- (void) notify_set_itimer_func(&Main_Timer, timefunc,
- ITIMER_REAL, &Main_Timer, 0) ;
- }
-
- return( value ) ;
- }
-
- static int auto_saved;
- /* really should come up with an "auto-word" with defined bits/fields */
-
- save_auto_state()
- {
- auto_saved = auto_pilot;
- auto_saved |= auto_fire << 1;
- }
-
- restore_auto_state()
- {
- auto_pilot = auto_saved & 0x1;
- auto_fire = (auto_saved >> 1) & 0x1;
- }
-
-
-
- #ifdef XGL
- dbuf_putcolormap(start, len, r,g,b)
- int start, len ;
- u_char *r,*g,*b ;
- {
- int i,j ;
-
- for(j=start; j<start+len; ++j)
- for(i=0; i<8; ++i)
- {
- ctab1[i+8*j].rgb.r = (float)r[j]/256. ;
- ctab1[i+8*j].rgb.g = (float)g[j]/256. ;
- ctab1[i+8*j].rgb.b = (float)b[j]/256. ;
- ctab2[8*i+j].rgb.r = (float)r[j]/256. ;
- ctab2[8*i+j].rgb.g = (float)g[j]/256. ;
- ctab2[8*i+j].rgb.b = (float)b[j]/256. ;
- }
- ctable.start_index = 0 ;
- ctable.length = 64 ;
- ctable.colors = ctab1 ;
- xgl_object_set(cmap1, XGL_CMAP_COLOR_TABLE, &ctable, 0) ;
- ctable.colors = ctab2 ;
- xgl_object_set(cmap2, XGL_CMAP_COLOR_TABLE, &ctable, 0) ;
- }
-
-
- dbuf_control(ctx, ctrl)
- Xgl_3d_ctx ctx ;
- int ctrl ;
- {
- int mask ;
- static int masks[2][4] = {{0,070,007,077}, {0,007,070,077}} ;
-
- mask = masks[dbuffer][ctrl] ;
-
- xgl_object_set(ctx, XGL_CTX_PLANE_MASK, mask, 0) ;
- }
-
-
- dbuf_swap()
- {
- dbuffer = 1-dbuffer ;
-
- xgl_object_set(Main_ras, XGL_RAS_COLOR_MAP,
- dbuffer == 0 ? cmap1 : cmap2, 0 ) ;
- }
- #endif XGL
-