Beispiel #1
0
/**************************************************************************
...
**************************************************************************/
void players_list_callback(Widget w, XtPointer client_data, 
			   XtPointer call_data)

{
  XawListReturnStruct *ret;

  ret = XawListShowCurrent(players_list);

  XtSetSensitive(players_meet_command, FALSE);
  XtSetSensitive(players_int_command, FALSE);
  if (ret->list_index != XAW_LIST_NONE) {
    struct player *pplayer = 
      player_by_number(list_index_to_player_index[ret->list_index]);

    if (pplayer->spaceship.state != SSHIP_NONE)
      XtSetSensitive(players_sship_command, TRUE);
    else
      XtSetSensitive(players_sship_command, FALSE);

    if (NULL != client.conn.playing && pplayer->is_alive) {
      XtSetSensitive(players_war_command,
		     client.conn.playing != pplayer
		     && !pplayers_at_war(client.conn.playing, pplayer));
    }

    if (NULL != client.conn.playing) {
      XtSetSensitive(players_vision_command,
		     gives_shared_vision(client.conn.playing, pplayer));

      XtSetSensitive(players_meet_command, can_meet_with_player(pplayer));
    }
    XtSetSensitive(players_int_command, can_intel_with_player(pplayer));
  }
}
Beispiel #2
0
/****************************************************************************
  Returns FALSE if there is no valid player at current index.
****************************************************************************/
static bool research_iter_player_valid(const struct iterator *it)
{
  struct research_iter *rit = RESEARCH_ITER(it);

  return (0 <= rit->index
          && ARRAY_SIZE(research_array) > rit->index
          && NULL != player_by_number(rit->index));
}
Beispiel #3
0
/**************************************************************************
...
**************************************************************************/
void players_sship_callback(Widget w, XtPointer client_data,
			    XtPointer call_data)
{
  XawListReturnStruct *ret = XawListShowCurrent(players_list);

  if (ret->list_index != XAW_LIST_NONE) {
    int player_index = list_index_to_player_index[ret->list_index];
    struct player *pplayer = player_by_number(player_index);

    popup_spaceship_dialog(pplayer);
  }
}
Beispiel #4
0
/**************************************************************************
  Returns the name of player or user, set in the same list.
**************************************************************************/
static const char *get_player_or_user_name(int id)
{
  size_t size = conn_list_size(game.all_connections);

  if (id < size) {
    return conn_list_get(game.all_connections, id)->username;
  } else {
    struct player *pplayer = player_by_number(id - size);
    if (pplayer) {
      return pplayer->name;
    } else {
      /* Empty slot. Relies on being used with comparison function
       * which can cope with NULL. */
      return NULL;
    }
  }
}
Beispiel #5
0
/**************************************************************************
...
**************************************************************************/
void players_meet_callback(Widget w, XtPointer client_data, 
			      XtPointer call_data)
{
  XawListReturnStruct *ret = XawListShowCurrent(players_list);

  if (ret->list_index != XAW_LIST_NONE) {
    int player_index = list_index_to_player_index[ret->list_index];
    struct player *pplayer = player_by_number(player_index);

    if (can_meet_with_player(pplayer)) {
      dsend_packet_diplomacy_init_meeting_req(&client.conn, player_index);
    } else {
      output_window_append(ftc_client,
                           _("You need an embassy to establish"
                             " a diplomatic meeting."));
    }
  }
}
Beispiel #6
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;
}