home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char sccsid[] = "@(#)robot_special.c 1.2 92/05/28 SMI" ;
- /* from robot_special.c 1.3 88/10/19 SMI */
- #endif
-
- /*
- * this file contains stuff that varies between fighter, robot etc.
- *
- * It contains these routines:
- *
- *
- * init_game_special(argc,argv)
- * initialize all graphics stuff (none for robot)
- *
- * init_communications()
- * sign on to the game. Called once at startup.
- *
- * special_welcome()
- * set id & team from data sent by daemon
- *
- * dstar_main_loop()
- * Start the game, calls notify_start(). Called once at startup.
- *
- * terminate_game()
- * called from sigint handler (not interrupt time) to shut down.
- *
- * 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_new_status(object)
- * called when an object changes status
- */
-
-
-
-
- #include <stdio.h>
- #include <sys/time.h>
- #include "dstar.h"
- #include "object_types.h"
- #ifndef XV
- #include <sunwindow/notify.h>
- #endif XV
-
- extern int optind ;
- extern char *optarg ;
-
- extern int status_display ;
-
- static int Killflag ;
- static int Last_Kill, Kill_Interval ;
-
-
- void timefunc() ;
- static int sigint() ;
-
-
- #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\
- -auto robot is aggressive\n\
- -help this list\n\
- hostname used to slave one local net to another\n" ;
-
-
-
-
-
- init_game_special(argc,argv)
- int argc ;
- char **argv ;
- {
- char *mastername = NULL ;
- int c ;
- extern fptr fighter_vector[VECTOR_LENGTH] ;
-
- auto_pilot = auto_fire = 0 ;
- Killflag = 0 ;
- Kill_Interval = 10 ;
- Last_Kill = -1 ;
-
- status_display = 0 ;
-
- while(--argc > 0)
- {
- ++argv ;
- if(strcmp(*argv,"-k")==0)
- {
- if(--argc > 0)
- Killflag = atoi(*++argv) ;
- }
-
- else if(strcmp(*argv,"-t")==0)
- {
- if(--argc > 0)
- Kill_Interval = atoi(*++argv) ;
- }
-
- else if(strcmp(*argv,"-free")==0)
- game_type = GAME_FREE ;
-
- else if(strcmp(*argv,"-teams")==0)
- game_type = GAME_TEAMS ;
-
- else if(strcmp(*argv,"-status")==0)
- status_display = 1 ;
-
- else if(strcmp(*argv,"-auto")==0)
- auto_fire = auto_pilot = 1 ;
-
- else if(strcmp(*argv,"-debug")==0)
- debug_level = 1 ;
-
- else if(strcmp(*argv,"-help")==0)
- {
- printf(help_info) ;
- exit(0) ;
- }
-
- else if(**argv == '-')
- printf("unknown option %s, '-help' for more info\n",*argv) ;
-
- else
- mastername = *argv ;
- }
-
-
- fighters[0] = FIGHTER1_DESC ;
- fighters[1] = FIGHTER2_DESC ;
-
- Me->id = -1 ;
- Me->team = 0 ;
- Me->score = 0 ;
- Me->class = OBJ_PLAYER ;
- Me->status = OBJ_ACTIVE ;
- Me->flags = (auto_pilot ? RADAR_FLAG : 0) | ROBOT_FLAG ;
- Me->Posn.x = (random() % 3000) - 1500 ;
- Me->Posn.y = (random() % 3000) - 1500 ;
- Me->Posn.z = (random() % 3000) - 1500 ;
- 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.1 ;
- 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)) ;
-
- Main_Timer.it_interval.tv_usec = 500000 ;
-
- init_netio("robot", mastername) ;
- }
-
-
-
- void
- special_welcome()
- {
- set_ship_description() ;
- }
-
-
-
- void
- dstar_main_loop()
- {
- notify_start() ;
- }
-
-
-
- int
- terminate_game()
- {
- (void) notify_set_itimer_func(&Main_Timer, timefunc,
- ITIMER_REAL, NULL, 0) ;
- net_remove_player(Me->id) ;
- net_flush() ;
- notify_stop() ;
- }
-
-
-
- void
- special_sleep_func()
- {}
-
-
- void
- normal_action()
- {
- if(Me->flags & RADAR_FLAG)
- do_radar() ;
- else
- Me->target = NULL ;
- control_ship(Me) ;
- if(Me->flags & LASER_FLAG)
- test_objects() ;
-
-
- if(Me->id != -1)
- {
- net_start_message( NULL ) ;
- send_status(Me) ; /* tell everyone where I am */
-
-
- if(Last_Kill == -1)
- Last_Kill = Now.tv_sec ;
- if(Killflag && Now.tv_sec - Last_Kill > Kill_Interval)
- {
- Object *object = &objects[0] ;
- int i ;
-
- for(i=0; i<MAX_OBJECTS; ++i)
- {
- if(object->class == OBJ_PLAYER &&
- object->status == OBJ_ACTIVE &&
- object != Me)
- switch(Killflag)
- {
- case 0:
- break ;
-
- case 1:
- if(strncmp(object->name, "robot",5) == 0)
- net_blow_away(Me, object) ;
- break ;
-
- case 2:
- if(strncmp(object->name, "robot",5) != 0)
- net_blow_away(Me, object) ;
- break ;
-
- case 3:
- net_blow_away(Me, object) ;
- break ;
- }
- object++ ;
- }
- Last_Kill = Now.tv_sec ;
- }
- }
- }
-
-
-
- void
- blast_action()
- {
- }
-
-
- /* this routine is called whenever the blast state changes */
-
-
- set_blast_state(state)
- Blast_State state ;
- {
- switch(state)
- {
- case B_FLASH:
- break ;
-
- case B_WAIT:
- break ;
-
- case B_NIL:
- Me->status = OBJ_ACTIVE ;
- Me->flags = (auto_pilot ? RADAR_FLAG : 0) | ROBOT_FLAG ;
- Me->Posn.x = (random() % 3000) - 1500 ;
- Me->Posn.y = (random() % 3000) - 1500 ;
- Me->Posn.z = (random() % 3000) - 1500 ;
- Me->Delta.x = 0.1 ;
- Me->Delta.y = 0.0 ;
- Me->Delta.z = 0.0 ;
- Me->Speed = DEFAULT_SPEED ;
- set_ship_description() ;
- break ;
- }
- }
-
-
-
-
-
- special_got_blasted(object)
- Object *object ;
- {}
-
-
-
-
- special_someone_got_blasted(object,victim)
- Object *object, *victim ;
- {}
-
-
-
-
- special_add_player(object)
- Object *object ;
- {}
-
-
-
-
- special_remove_player(object)
- Object *object ;
- {}
-
-
-
- special_new_status(object)
- Object *object ;
- {}
-
-
-
-
-
-
- static
- set_ship_description()
- {
- Me->description = fighters[Me->team % MAX_FIGHTERS] ;
- }
-
-
-
- missile_armed(id)
- int id ;
- {
- puts("?just got Net_missile") ;
- }
-
-
-
- missile_shot(id)
- int id ;
- {
- puts("?just got missile_shot") ;
- }
-