home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2611 / robot_special.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-23  |  5.9 KB  |  371 lines

  1. #ifndef lint
  2. static    char    sccsid[] = "@(#)robot_special.c 1.2 92/05/28 SMI" ;
  3.     /* from robot_special.c 1.3 88/10/19 SMI */
  4. #endif
  5.  
  6. /*
  7.  * this file contains stuff that varies between fighter, robot etc.
  8.  *
  9.  * It contains these routines:
  10.  *
  11.  *
  12.  * init_game_special(argc,argv)
  13.  *    initialize all graphics stuff (none for robot)
  14.  *
  15.  * init_communications()
  16.  *    sign on to the game.    Called once at startup.
  17.  *
  18.  * special_welcome()
  19.  *    set id & team from data sent by daemon
  20.  *
  21.  * dstar_main_loop()
  22.  *    Start the game, calls notify_start().  Called once at startup.
  23.  *
  24.  * terminate_game()
  25.  *    called from sigint handler (not interrupt time) to shut down.
  26.  *
  27.  * normal_action()
  28.  *    called from time function, once per slice
  29.  *
  30.  * blast_action()
  31.  *    called from time function, once per time slice while dead
  32.  *
  33.  * set_blast_state()
  34.  *    called from time function, once per state change while dead
  35.  *
  36.  * special_add_player(object)
  37.  *    called when a new object joins the game
  38.  *
  39.  * special_remove_player(object)
  40.  *    called when an object leaves the game
  41.  *
  42.  * special_new_status(object)
  43.  *    called when an object changes status
  44.  */
  45.  
  46.  
  47.  
  48.  
  49. #include <stdio.h>
  50. #include <sys/time.h>
  51. #include "dstar.h"
  52. #include "object_types.h"
  53. #ifndef XV
  54. #include <sunwindow/notify.h>
  55. #endif XV
  56.  
  57. extern    int    optind ;
  58. extern    char    *optarg ;
  59.  
  60. extern    int    status_display ;
  61.  
  62. static    int    Killflag ;
  63. static    int    Last_Kill, Kill_Interval ;
  64.  
  65.  
  66.     void    timefunc() ;
  67. static    int    sigint() ;
  68.  
  69.  
  70. #define    MAX_FIGHTERS    2
  71.  
  72. static    int    fighters[MAX_FIGHTERS] ;
  73.  
  74.  
  75.  
  76. static    char    *help_info ="\
  77. -k n        kill flag, 1=robots, 2=humans, 3=both\n\
  78. -t n        time interval for above\n\
  79. -free        free-for-all\n\
  80. -teams        players divided into two teams\n\
  81. -auto        robot is aggressive\n\
  82. -help        this list\n\
  83. hostname    used to slave one local net to another\n" ;
  84.  
  85.  
  86.  
  87.  
  88.  
  89. init_game_special(argc,argv)
  90.     int    argc ;
  91.     char    **argv ;
  92. {
  93.     char    *mastername = NULL ;
  94.     int    c ;
  95. extern    fptr    fighter_vector[VECTOR_LENGTH] ;
  96.  
  97.     auto_pilot = auto_fire = 0 ;
  98.     Killflag = 0 ;
  99.     Kill_Interval = 10 ;
  100.     Last_Kill = -1 ;
  101.  
  102.     status_display = 0 ;
  103.  
  104.     while(--argc > 0)
  105.     {
  106.       ++argv ;
  107.       if(strcmp(*argv,"-k")==0)
  108.       {
  109.         if(--argc > 0)
  110.           Killflag = atoi(*++argv) ;
  111.       }
  112.  
  113.       else if(strcmp(*argv,"-t")==0)
  114.       {
  115.         if(--argc > 0)
  116.           Kill_Interval = atoi(*++argv) ;
  117.       }
  118.  
  119.       else if(strcmp(*argv,"-free")==0)
  120.         game_type = GAME_FREE ;
  121.  
  122.       else if(strcmp(*argv,"-teams")==0)
  123.         game_type = GAME_TEAMS ;
  124.  
  125.       else if(strcmp(*argv,"-status")==0)
  126.         status_display = 1 ;
  127.  
  128.       else if(strcmp(*argv,"-auto")==0)
  129.         auto_fire = auto_pilot = 1 ;
  130.  
  131.       else if(strcmp(*argv,"-debug")==0)
  132.         debug_level = 1 ;
  133.  
  134.       else if(strcmp(*argv,"-help")==0)
  135.       {
  136.         printf(help_info) ;
  137.         exit(0) ;
  138.       }
  139.  
  140.       else if(**argv == '-')
  141.         printf("unknown option %s, '-help' for more info\n",*argv) ;
  142.  
  143.       else
  144.         mastername = *argv ;
  145.     }
  146.  
  147.  
  148.     fighters[0] = FIGHTER1_DESC ;
  149.     fighters[1] = FIGHTER2_DESC ;
  150.  
  151.     Me->id = -1 ;
  152.     Me->team = 0 ;
  153.     Me->score = 0 ;
  154.     Me->class = OBJ_PLAYER ;
  155.     Me->status = OBJ_ACTIVE ;
  156.     Me->flags = (auto_pilot ? RADAR_FLAG : 0) | ROBOT_FLAG ;
  157.     Me->Posn.x = (random() % 3000) - 1500 ;
  158.     Me->Posn.y = (random() % 3000) - 1500 ;
  159.     Me->Posn.z = (random() % 3000) - 1500 ;
  160.     Me->Forward.x = 0.0 ;
  161.     Me->Forward.y = 0.0 ;
  162.     Me->Forward.z = 1.0 ;
  163.     Me->Up.x = 0.0 ;
  164.     Me->Up.y = 1.0 ;
  165.     Me->Up.z = 0.0 ;
  166.     Me->Right.x = 1.0 ;
  167.     Me->Right.y = 0.0 ;
  168.     Me->Right.z = 0.0 ;
  169.     Me->Delta.x = 0.1 ;
  170.     Me->Delta.y = 0.0 ;
  171.     Me->Delta.z = 0.0 ;
  172.     Me->Pointing = Me->Forward ;
  173.     Me->Speed = DEFAULT_SPEED ;
  174.     Me->description = FIGHTER1_DESC ;
  175.     bcopy(fighter_vector, Me->f_vector, sizeof(fighter_vector)) ;
  176.  
  177.     Main_Timer.it_interval.tv_usec = 500000 ;
  178.  
  179.     init_netio("robot", mastername) ;
  180. }
  181.  
  182.  
  183.  
  184. void
  185. special_welcome()
  186. {
  187.     set_ship_description() ;
  188. }
  189.  
  190.  
  191.  
  192. void
  193. dstar_main_loop()
  194. {
  195.     notify_start() ;
  196. }
  197.  
  198.  
  199.  
  200. int
  201. terminate_game()
  202. {
  203.     (void) notify_set_itimer_func(&Main_Timer, timefunc,
  204.         ITIMER_REAL, NULL, 0) ;
  205.     net_remove_player(Me->id) ;
  206.     net_flush() ;
  207.     notify_stop() ;
  208. }
  209.  
  210.  
  211.  
  212. void
  213. special_sleep_func()
  214. {}
  215.  
  216.  
  217. void
  218. normal_action()
  219. {
  220.     if(Me->flags & RADAR_FLAG)
  221.       do_radar() ;
  222.     else
  223.       Me->target = NULL ;
  224.     control_ship(Me) ;
  225.     if(Me->flags & LASER_FLAG)
  226.       test_objects() ;
  227.  
  228.  
  229.     if(Me->id != -1)
  230.     {
  231.       net_start_message( NULL ) ;
  232.       send_status(Me) ;    /* tell everyone where I am */
  233.  
  234.  
  235.       if(Last_Kill == -1)
  236.         Last_Kill = Now.tv_sec ;
  237.       if(Killflag  &&  Now.tv_sec - Last_Kill > Kill_Interval)
  238.       {
  239.         Object *object = &objects[0] ;
  240.         int    i ;
  241.  
  242.         for(i=0; i<MAX_OBJECTS; ++i)
  243.         {
  244.           if(object->class == OBJ_PLAYER  &&
  245.          object->status == OBJ_ACTIVE  &&
  246.          object != Me)
  247.         switch(Killflag)
  248.         {
  249.           case 0:
  250.             break ;
  251.  
  252.           case 1:
  253.             if(strncmp(object->name, "robot",5) == 0)
  254.               net_blow_away(Me, object) ;
  255.             break ;
  256.  
  257.           case 2:
  258.             if(strncmp(object->name, "robot",5) != 0)
  259.               net_blow_away(Me, object) ;
  260.             break ;
  261.  
  262.           case 3:
  263.             net_blow_away(Me, object) ;
  264.             break ;
  265.         }
  266.           object++ ;
  267.         }
  268.         Last_Kill = Now.tv_sec ;
  269.       }
  270.     }
  271. }
  272.  
  273.  
  274.  
  275. void
  276. blast_action()
  277. {
  278. }
  279.  
  280.  
  281. /* this routine is called whenever the blast state changes */
  282.  
  283.  
  284. set_blast_state(state)
  285.     Blast_State    state ;
  286. {
  287.     switch(state)
  288.     {
  289.       case B_FLASH:
  290.         break ;
  291.  
  292.       case B_WAIT:
  293.         break ;
  294.  
  295.       case B_NIL:
  296.         Me->status = OBJ_ACTIVE ;
  297.         Me->flags = (auto_pilot ? RADAR_FLAG : 0) | ROBOT_FLAG ;
  298.         Me->Posn.x = (random() % 3000) - 1500 ;
  299.         Me->Posn.y = (random() % 3000) - 1500 ;
  300.         Me->Posn.z = (random() % 3000) - 1500 ;
  301.         Me->Delta.x = 0.1 ;
  302.         Me->Delta.y = 0.0 ;
  303.         Me->Delta.z = 0.0 ;
  304.         Me->Speed = DEFAULT_SPEED ;
  305.         set_ship_description() ;
  306.         break ;
  307.     }
  308. }
  309.  
  310.  
  311.  
  312.  
  313.  
  314. special_got_blasted(object)
  315.     Object    *object ;
  316. {}
  317.  
  318.  
  319.  
  320.  
  321. special_someone_got_blasted(object,victim)
  322.     Object    *object, *victim ;
  323. {}
  324.  
  325.  
  326.  
  327.  
  328. special_add_player(object)
  329.     Object    *object ;
  330. {}
  331.  
  332.  
  333.  
  334.  
  335. special_remove_player(object)
  336.     Object    *object ;
  337. {}
  338.  
  339.  
  340.  
  341. special_new_status(object)
  342.     Object    *object ;
  343. {}
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350. static
  351. set_ship_description()
  352. {
  353.     Me->description = fighters[Me->team % MAX_FIGHTERS] ;
  354. }
  355.  
  356.  
  357.  
  358. missile_armed(id)
  359.     int    id ;
  360. {
  361.     puts("?just got Net_missile") ;
  362. }
  363.  
  364.  
  365.  
  366. missile_shot(id)
  367.     int    id ;
  368. {
  369.     puts("?just got missile_shot") ;
  370. }
  371.