Example #1
0
void setup_exchange_player_number(void)
{
  struct PlayerInfo *player;
  struct Packet *pckt;
  int i,k;
  SYNCDBG(6,"Starting");
  clear_packets();
  player = get_my_player();
  pckt = get_packet_direct(my_player_number);
  set_packet_action(pckt, PckA_InitPlayerNum, player->field_2C, settings.video_rotate_mode, 0, 0);
  if (LbNetwork_Exchange(pckt))
      ERRORLOG("Network Exchange failed");
  k = 0;
  for (i=0; i<NET_PLAYERS_COUNT; i++)
  {
      pckt = get_packet_direct(i);
      if ((net_player_info[i].active) && (pckt->action == PckA_InitPlayerNum))
      {
          player = get_player(k);
          player->id_number = k;
          player->field_0 |= 0x01;
          if (pckt->field_8 < 1)
            player->field_4B5 = 2;
          else
            player->field_4B5 = 5;
          player->field_2C = pckt->field_6;
          init_player(player, 0);
          strncpy(player->field_15,net_player[i].name,sizeof(struct TbNetworkPlayerName));
          k++;
      }
  }
}
Example #2
0
bool update(const char * field, std::vector<uint8_t> data) {
    if (!strcmp(field, "dlpkt")) {
        return delete_packet(data);
    } else if (!strcmp(field, "dlcha")) {
        return delete_channel(data);
    } else if (!strcmp(field, "pnum")) {
        return set_pnumber(data);
    } else if (!strcmp(field, "chan")) {
        return set_channel(data);
    } else if (!strcmp(field, "pol")) {
        set_poll(data);
    } else if (!strcmp(field, "dir")) {
        const char * dirStr = byteVec2cstr(data);
        if (!strcmp(dirStr, "pos"))
            set_direction(DIR_POS);
        else if (!strcmp(dirStr, "neg"))
            set_direction(DIR_NEG);
        else return false;
    } else if (!strcmp(field, "data")) {
        return set_current(data);
    } else if (!strcmp(field, "wait")) {
        set_delay(data);
    } else if (!strcmp(field, "send")) {
        flag_return = true;
        send_packets();
    } else if (!strcmp(field, "reset")) {
        send_global_reset();
    } else if (!strcmp(field, "glob")) {
        set_global();
    } else if (!strcmp(field, "conn")) {
        flag_return = true;
        return connect_serial();
    } else if (!strcmp(field, "exit")) {
        return exit();
    } else if (!strcmp(field, "clrpks")) {
        clear_packets();
    } else if (!strcmp(field, "prev")) {
        if (debug_) preview_packets();
        preview_packet_bytes();
        flag_return = true;
    } else { return false; }
    return true;
}
Example #3
0
void fronttorture_input(void)
{
    struct PlayerInfo *player;
    struct Packet *pckt;
    long x,y;
    PlayerNumber plyr_idx;
    long door_id;
    clear_packets();
    player = get_my_player();
    pckt = get_packet(my_player_number);
    // Get inputs and create packet
    if (player->victory_state == VicS_WonLevel)
    {
        if (left_button_clicked)
        {
            torture_left_button = 1;
            left_button_clicked = 0;
        }
        if ((lbKeyOn[KC_SPACE]) || (lbKeyOn[KC_RETURN]) || (lbKeyOn[KC_ESCAPE]))
        {
            lbKeyOn[KC_SPACE] = 0;
            lbKeyOn[KC_RETURN] = 0;
            lbKeyOn[KC_ESCAPE] = 0;
            pckt->action |= 0x01;
        }
        if (torture_left_button)
            pckt->action |= 0x02;
        if (left_button_held)
            pckt->action |= 0x04;
        pckt->actn_par1 = GetMouseX();
        pckt->actn_par2 = GetMouseY();
    }
    // Exchange packet with other players
    if ((game.system_flags & GSF_NetworkActive) != 0)
    {
        if (LbNetwork_Exchange(pckt))
            ERRORLOG("LbNetwork_Exchange failed");
    }
    // Determine the controlling player and get his mouse coords
    for (plyr_idx=0; plyr_idx < PLAYERS_COUNT; plyr_idx++)
    {
        player = get_player(plyr_idx);
        pckt = get_packet(plyr_idx);
        if ((pckt->action != 0) && (player->victory_state == VicS_WonLevel))
            break;
    }
    if (plyr_idx < PLAYERS_COUNT)
    {
        x = pckt->actn_par1;
        y = pckt->actn_par2;
    } else
    {
        plyr_idx = my_player_number;
        player = get_player(plyr_idx);
        pckt = get_packet(plyr_idx);
        x = 0;
        y = 0;
    }
    if ((pckt->action & 0x01) != 0)
    {
        frontend_set_state(FeSt_LEVEL_STATS);
        if ((game.system_flags & GSF_NetworkActive) != 0)
            LbNetwork_Stop();
        return;
    }
    // Get active door
    door_id = torture_door_over_point(x,y);
    if ((torture_door_selected != -1) && (torture_door_selected != door_id))
        door_id = -1;
    // Make the action
    if (door_id == -1)
      torture_left_button = 0;
    switch (torture_state.action)
    {
    case 0:
        if (door_id != -1)
        {
          torture_state.action = 1;
          torture_sprite_direction = 1;
          torture_door_selected = door_id;
          torture_sprite_frame = 3;
          torture_end_sprite = 7;
        }
        break;
    case 1:
        if (torture_sprite_frame == torture_end_sprite)
        {
          if (door_id == -1)
          {
            torture_state.action = 2;
            torture_sprite_frame = 8;
            torture_end_sprite = 4;
            torture_sprite_direction = -1;
          } else
          if ((pckt->action & (0x02|0x04)) != 0)
          {
            torture_state.action = 3;
            torture_left_button = 0;
            torture_sprite_frame = 7;
            torture_end_sprite = 11;
            torture_sprite_direction = 1;
            torture_play_sound(torture_door_selected, true);
          }
        }
        break;
    case 2:
        if (torture_sprite_frame == torture_end_sprite)
        {
          torture_state.action = 0;
          torture_door_selected = -1;
        }
        break;
    case 3:
        if (torture_sprite_frame == torture_end_sprite)
        {
          if (((pckt->action & 0x04) == 0) || (door_id == -1))
          {
            torture_state.action = 4;
            torture_sprite_frame = 12;
            torture_end_sprite = 8;
            torture_sprite_direction = -1;
            torture_play_sound(torture_door_selected, false);
          }
        }
        break;
    case 4:
        if (torture_sprite_frame == torture_end_sprite)
        {
          torture_state.action = 1;
          torture_sprite_frame = 7;
          torture_end_sprite = 7;
        }
        break;
    }
}