Пример #1
0
void inl_draft_begin()
{
  int h;
  struct player *j;

  status->gameup &= ~GU_INL_DRAFTED;

  context->inl_draft = INL_DRAFT_MOVING_TO_POOL;
  context->inl_pool = 0;
  context->inl_home_pick = 0;
  context->inl_away_pick = 0;

  for (h = 0, j = &players[0]; h < MAXPLAYER; h++, j++) {
    if (inl_draft_ignore(j)) continue;
    j->p_desspeed = 0;
    bay_release(j);
    j->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN |
                    PFCLOAK);
    j->p_flags |= PFSEEN;
    inl_draft_highlight_off(j);
    inl_draft_assign_to_pool(j);
    inl_draft_place(j);
  }

  status->gameup |= GU_INL_DRAFTING;
  pmessage(0, MALL, "GOD->ALL", "The captains have agreed to hold a draft.");
}
Пример #2
0
int main(int argc, char **argv)
{
  int player;
  char buf[1000];
  int c;

  if (argc < 2)
    Usage();
  getpath();

  openmem(0);

  player=atoi(argv[1]);
  if ((player == 0) && (*argv[1] != '0')) {
    c = *argv[1];
    if (c >= 'a' && c <= 'z')
      player = c - 'a' + 10;
    else {
      Usage();
    }
  }
  if (player >= MAXPLAYER) {
    printf("MAXPLAYER is set to %d, and you want %d?\n", 
	   MAXPLAYER, player);
    exit(1);
  }

  /* request to free slot? */
  if (argc > 2) {
    if (*argv[2] == 'F') {
      int pid;
      pid = players[player].p_process;
      players[player].p_disconnect = BADVERSION_DENIED;
      usleep(200000); /* guarantee an update will occur */
      if (players[player].p_status == PFREE) exit(0); /* slot free, he went */
      if (pid != players[player].p_process) exit(0); /* pid changed, he went */
      if (players[player].p_process > 1) { /* p_disconnect must have failed */
	if (kill(players[player].p_process, SIGTERM) == 0)
	  exit(0);
      }
      /* if we have no pid_t, or the pid_t was wrong, free slot */
      freeslot(&players[player]);
      exit(0);
    }
  }

  if (players[player].p_status != PALIVE) {
    if(players[player].p_status != POBSERV) {
      printf("Slot is not alive.\n");
      exit(1);
    }
  }

  if (argc > 2)
    switch (*argv[2]) {
    case 'T': { /* change team */
      int team;
	      
      switch (argv[2][1]) {
      case 'f': team = 1; break;
      case 'r': team = 2; break;
      case 'k': team = 4; break;
      case 'o': team = 8; break;
      default:  team = 0;
      }	    
      change_team_quietly(players[player].p_no, team, players[player].p_team);
    }
    break;
    case 'e': /* eject (GHOSTTIME applies in daemon) */
      sprintf(buf, "GOD->ALL  %s has been ejected from the game.", 
	      players[player].p_longname);		    
      players[player].p_whydead=KQUIT;
      players[player].p_explode=10;
      players[player].p_status=3;
      players[player].p_whodead=0;
      amessage(buf, 0, MALL);
      break;
    case 't': /* teleport */
      switch(argv[2][1]) {
      case 'f':
	p_x_y_set(&players[player], planets[0].pl_x, planets[0].pl_y);
	break;
      case 'r':
	p_x_y_set(&players[player], planets[10].pl_x, planets[10].pl_y);
	break;
      case 'k':
	p_x_y_set(&players[player], planets[20].pl_x, planets[20].pl_y);
	break;
      case 'o':
	p_x_y_set(&players[player], planets[30].pl_x, planets[30].pl_y);
	break;
      case 'c':
	p_x_y_set(&players[player], GWIDTH/2, GWIDTH/2);
	break;
      default:
	printf("Valid teleports: frkoc.\n");
	exit(1);
      }
      break;
    case 's': /* ship type change */
      switch (argv[2][1]) {
      case 'a': refit(&players[player], ASSAULT); break;
      case 'b': refit(&players[player], BATTLESHIP); break;
      case 'c': refit(&players[player], CRUISER); break;
      case 'd': refit(&players[player], DESTROYER); break;
      case 'g': refit(&players[player], SGALAXY); break;
      case 's': refit(&players[player], SCOUT); break;
      case 'o': refit(&players[player], STARBASE); break;
      case 'A': refit(&players[player], ATT); break;
      case 'S': 
	getship(&players[player].p_ship, SCOUT);
	players[player].p_ship.s_torpdamage = 1;
	players[player].p_ship.s_torpfuse = 8;
	players[player].p_ship.s_phaserdamage = 1;
	players[player].p_ship.s_plasmadamage = 1;
	players[player].p_ship.s_plasmaspeed = 1;
	players[player].p_ship.s_plasmaturns = 1;
	players[player].p_ship.s_maxshield = 750;
	break;
      default:
	printf("Valid ship types: abcdgsoAS.\n");
	exit(1);
	break;
      }
      players[player].p_damage = 0;
      players[player].p_shield = players[player].p_ship.s_maxshield;
      players[player].p_wtemp = 0;
      players[player].p_etemp = 0;
      players[player].p_fuel = players[player].p_ship.s_maxfuel;
      if (argv[2][1] == 'o') players[player].p_flags |= PFDOCKOK;
      break;
    case 'p':		/* puck? */
      players[player].p_ship.s_tractstr = 1;
      players[player].p_ship.s_torpdamage = -1;
      players[player].p_ship.s_plasmadamage = -1;
      players[player].p_ship.s_phaserdamage = -1;
      players[player].p_hostile = 0;
      players[player].p_swar = 0;
      players[player].p_war = 0;
      players[player].p_team = 0;	/* indep */
      players[player].p_ship.s_type = SCOUT;
      players[player].p_ship.s_mass = 200;
      players[player].p_ship.s_repair = 30000;
      break;
    case 'S':		/* super ship */
      players[player].p_ship.s_maxshield = 750;
      players[player].p_shield = 750;
      players[player].p_ship.s_maxdamage = 750;
      players[player].p_damage = 0;
      players[player].p_ship.s_maxegntemp = 5000;
      players[player].p_etemp = 0;
      break;
    case 'D':		/* demote, but not beyond ensign */
      if(players[player].p_stats.st_rank == 0)
	players[player].p_stats.st_rank++;

      --players[player].p_stats.st_rank;
      break;
    case 'P':		/* promote, but not beyond admiral */
      if( players[player].p_stats.st_rank < (NUMRANKS - 1) ) 
	++players[player].p_stats.st_rank;
      break;
    case 'k':		/* kill increment */
      if (strlen(argv[2]) > 1)
        players[player].p_kills += atoi(argv[2]+1);
      else
        players[player].p_kills += 1.0;
      break;
    case 'a':		/* army increment */
      if (strlen(argv[2]) > 1) 
	players[player].p_armies = atoi(argv[2]+1);
      else 
	players[player].p_armies += 6;
      break;
    case 'C':		/* clock surrender reset */
      teams[players[player].p_team].te_surrender = 6;
      break;
    case 'h':		/* harm */
      players[player].p_shield = 0;
      players[player].p_damage = players[player].p_ship.s_maxdamage/2;
      break;
    case 'H':           /* hack */
      {
      struct player *me = &players[player];
      /* make independent and hostile to only prior team */
      int team = players[player].p_team;
      players[player].p_hostile = team;
      players[player].p_swar = team;
      players[player].p_war = team;
      players[player].p_team = 0;
      sprintf(players[player].p_mapchars, "%c%c", 
	      teamlet[players[player].p_team], shipnos[player]);
      sprintf(players[player].p_longname, "%s (%s)", 
	      players[player].p_name, players[player].p_mapchars);
      /* cripple */
      players[player].p_shield = 0;
      players[player].p_damage = players[player].p_ship.s_maxdamage/2;
      /* raise shields */
      players[player].p_flags |= PFSHIELD;
      players[player].p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
      /* break tractors and decloak */
      me->p_flags &= ~(PFTRACT | PFPRESS);
      me->p_flags &= ~PFCLOAK;
      /* set speed 0 */
      me->p_desspeed = 0;
      bay_release(me);
      me->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
      /* make unable to act */
      players[player].p_flags |= PFTWARP;
      /* show as puck */
      players[player].p_ship.s_type = SCOUT;
      }
      break;
    case 'u':           /* raise shields */
      players[player].p_flags |= PFSHIELD;
      players[player].p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
      break;
    case 'd':           /* lower shields */
      players[player].p_flags &= ~(PFSHIELD);
      break;
    case 'R':		/* robot kill? */
      if (players[player].p_flags & PFROBOT) {
	players[player].p_ship.s_type = STARBASE;
	players[player].p_whydead=KPROVIDENCE;
	players[player].p_explode=10;
	players[player].p_status=3;
	players[player].p_whodead=0;
      }
      break;
    case 'L':		/* starbase loss adjust */
#ifdef LTD_STATS
#ifndef LTD_PER_RACE
      players[player].p_stats.ltd[0][LTD_SB].deaths.total--;
#endif
#else
      players[player].p_stats.st_sblosses--;
#endif
      break;
    case 'r':           /* repair ship */
      p_heal(&players[player]);
      break;
    case 'f':		/* flatten kills / armies */
      players[player].p_kills = 0;
      players[player].p_armies = 0;
      break;
    case 'n':		/* toggle carry flag */
      players[player].p_no_pick = !players[player].p_no_pick;
      sprintf(buf, "GOD->%s  %s %s pick up armies",
              team_code(players[player].p_team),
              players[player].p_longname,
              players[player].p_no_pick ?
                  "is no longer able to" : "can once again");
      amessage(buf, players[player].p_team, MTEAM);
      break;
    default:
      Usage();
    }			/* end switch */
  else {
    sprintf(buf, "GOD->ALL  %s was utterly obliterated.", 
	    players[player].p_longname);
    players[player].p_ship.s_type=STARBASE;
    players[player].p_whydead=KPROVIDENCE;
    players[player].p_explode=10;
    players[player].p_status=3;
    players[player].p_whodead=0;
    amessage(buf, 0, MALL);
  }
  return 0;
}
Пример #3
0
int setship(const char *cmds)
{
  const char delimiters[] = " ";
  char *copy, *token;
  struct player *me;

  copy = strdup(cmds);
  token = strtok(copy, delimiters);
  if (!token) { usage(); return 1; }
  openmem(0);

 state_0:
  me = player_by_number(token);
  if (me == NULL) {
    fprintf(stderr, "unknown slot\n");
    exit(1);
  }

 state_1:
  if (!(token = strtok (NULL, delimiters))) return 0;

  if (!strcmp(token, "show-position")) {
    printf("frame %d", context->frame);
    printf(" speed %d", me->p_speed);
    printf(" dir %d", me->p_dir);
    printf(" position %d %d", me->p_x, me->p_y);
    printf("\n");
    goto state_1;
  }

  if (!strcmp(token, "position")) {
    int p_x, p_y;
    if (!(token = strtok (NULL, delimiters))) return 0;
    p_x = atoi(token);
    if (!(token = strtok (NULL, delimiters))) return 0;
    p_y = atoi(token);
    p_x_y_set(me, p_x, p_y);
    goto state_1;
  }

  if (!strcmp(token, "dir")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    me->p_dir = atoi(token);
    me->p_desdir = atoi(token);
    bay_release(me);
    me->p_flags &= ~(PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
    goto state_1;
  }

  if (!strcmp(token, "speed")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    me->p_desspeed = atoi(token);
    me->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
    me->p_flags &= ~(PFPLOCK | PFPLLOCK);
    goto state_1;
  }

  if (!strcmp(token, "wait-for-stop")) {
    while (me->p_speed) usleep(20000);
    goto state_1;
  }

  if (!strcmp(token, "lock-planet")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    struct planet *pl = planet_find(token);
    //* lock on, from lock_planet() in interface.c 
    me->p_flags |= PFPLLOCK;
    me->p_flags &= ~(PFPLOCK|PFORBIT|PFBEAMUP|PFBEAMDOWN|PFBOMB);
    me->p_planet = pl->pl_no;
    goto state_1;
  }

  if (!strcmp(token, "wait-for-orbit")) {
    while (!(me->p_flags & PFORBIT)) usleep(20000);
    goto state_1;
  }

  if (!strcmp(token, "wobble")) {
    t_attribute |= TWOBBLE;
    goto state_1;
  }

  if (!strcmp(token, "no-wobble")) {
    t_attribute &= ~TWOBBLE;
    goto state_1;
  }

  if (!strcmp(token, "torp-speed")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    t_torpspeed = atoi(token);
    goto state_1;
  }

  if (!strcmp(token, "fire-test-torpedo")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    struct ship *myship = &me->p_ship;
    struct torp *k = t_find(me, TFREE);
    me->p_ntorp++;
    k->t_status = TMOVE;
    k->t_type = TPLASMA;
    k->t_attribute = t_attribute;
    k->t_owner = me->p_no;
    t_x_y_set(k, me->p_x, me->p_y);
    k->t_turns  = myship->s_torpturns;
    k->t_damage = 0;
    k->t_gspeed = (t_torpspeed == -1 ? myship->s_torpspeed : t_torpspeed)
      * WARP1;
    k->t_fuse   = 500;
    k->t_dir    = atoi(token);
    k->t_war    = me->p_war;
    k->t_team   = me->p_team;
    k->t_whodet = NODET;
    goto state_1;
  }

  if (!strcmp(token, "show-test-torpedo-position")) {
    struct torp *k = t_find(me, TMOVE);
    if (k != NULL) {
      printf("torp %d x %d y %d\n", k->t_dir, k->t_x, k->t_y);
    }
    goto state_1;
  }

  if (!strcmp(token, "destroy-test-torpedo")) {
    struct torp *k = t_find(me, TMOVE);
    if (k != NULL) {
      k->t_status = TOFF;
    }
    goto state_1;
  }

  if (!strcmp(token, "monitor-coordinates")) {
    for (;;) {
      printf("p_x %X p_y %X p_x_internal %X p_y_internal %X\n", me->p_x, me->p_y, me->p_x_internal, me->p_y_internal);
      usleep(20000);
    }
    goto state_1;
  }

  if (!strcmp(token, "monitor-docking")) {
    for (;;) {
      printf("p_flags & PFDOCK %X p_dock_with %X p_dock_bay %X\n", me->p_flags & PFDOCK, me->p_dock_with, me->p_dock_bay);
      usleep(20000);
    }
    goto state_1;
  }

  if (!strcmp(token, "sleep")) {
    if (!(token = strtok(NULL, delimiters))) return 0;
    sleep(atoi(token));
    goto state_1;
  }

  if (!strcmp(token, "set-inl-draft")) {
    if (!(token = strtok(NULL, delimiters))) return 0;
    me->p_inl_draft = atoi(token);
    goto state_1;
  }

  if (!strcmp(token, "monitor-inl-draft")) {
    for (;;) {
      printf("p_inl_captain %d p_inl_draft %d (%s) p_inl_x %d p_inl_y %d p_inl_pick %d\n", me->p_inl_captain, me->p_inl_draft, inl_draft_name(me->p_inl_draft), me->p_inl_x, me->p_inl_y, me->p_inl_pick);
      usleep(20000);
    }
    goto state_1;
  }

  if (!strcmp(token, "show-inl-draft")) {
    printf("p_inl_captain %d p_inl_draft %d (%s) p_inl_x %d p_inl_y %d p_inl_pick %d\n", me->p_inl_captain, me->p_inl_draft, inl_draft_name(me->p_inl_draft), me->p_inl_x, me->p_inl_y, me->p_inl_pick);
    goto state_1;
  }

  if (!strcmp(token, "wait-for-inl-draft-to-end")) {
    for (;;) {
      if (me->p_inl_draft == INL_DRAFT_OFF) exit(0);
      usleep(20000);
    }
    goto state_1;
  }

  if (!strcmp(token, "player")) {
    me->p_flags &= ~PFOBSERV;
    me->p_status = PALIVE;
    goto state_1;
  }
  if (!strcmp(token, "observer")) {
    me->p_flags |= PFOBSERV;
    me->p_status = POBSERV;
    goto state_1;
  }

  if (!strcmp(token, "captain")) {
    me->p_inl_captain = 1;
    goto state_1;
  }

  if (!strcmp(token, "no-captain")) {
    me->p_inl_captain = 0;
    goto state_1;
  }

  if (!strcmp(token, "damage")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    me->p_damage = me->p_ship.s_maxdamage - atoi(token);
    goto state_1;
  }

  if (!strcmp(token, "shields")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    me->p_shield = atoi(token);
    goto state_1;
  }

  if (!strcmp(token, "fuel")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    me->p_fuel = atoi(token);
    goto state_1;
  }

  if (!strcmp(token, "disconnect")) {
    if (!(token = strtok (NULL, delimiters))) return 0;
    me->p_disconnect = atoi(token);
    goto state_1;
  }

  goto state_0;
}