Beispiel #1
0
  //---------------------------------------------- CHANGE RACE -----------------------------------------------
  void GameImpl::_changeRace(int slot, BWAPI::Race race)
  {
    if ( race == Races::Unknown || race == Races::None )
      return;

    // Obtain the single player dialog
    BW::dialog *custom = BW::FindDialogGlobal("Create");
    if ( custom )
    {
      slot = clamp(slot, 0, 7);
      // Apply the single player change
      BW::dialog *slotCtrl = custom->findIndex((short)(28 + slot));  // 28 is the CtrlID of the first slot
      if ( slotCtrl && (int)slotCtrl->getSelectedValue() != race )
        slotCtrl->setSelectedByValue(race);
      return;
    }

    // Obtain the multi-player dialog
    custom = BW::FindDialogGlobal("Chat");
    if ( !custom ) // return if not found
      return;

    // Obtain the countdown control
    BW::dialog *countdown = custom->findIndex(24);
    if ( !countdown ) // return if not found
      return;

    // Obtain the countdown control's text
    const char *txt = countdown->getText();
    if ( txt && txt[0] && txt[0] < '2' )
      return; // return if the countdown is less than 2

    // Send the change race command for multi-player
    QUEUE_COMMAND(BW::Orders::RequestChangeRace, slot, race);
  }
Beispiel #2
0
void __stdcall DrawDialogHook(BW::bitmap *pSurface, BW::bounds *pBounds)
{
  if ( BW::pOldDrawDialogProc && !hideHUD )
    BW::pOldDrawDialogProc(pSurface, pBounds);

  if ( *BW::BWDATA_gwGameMode == BW::GAME_GLUES )
    BWAPI::BroodwarImpl.onMenuFrame();

  BW::dialog *timeout = BW::FindDialogGlobal("TimeOut");
  if ( timeout )
  {
    BW::dialog *dropbtn = timeout->findIndex(2);
    if ( !dropbtn->isDisabled() )
      BWAPI::BroodwarImpl.dropPlayers();
  }

  // NOSOUND config option
  if ( !nosound )
  {
    nosound = true;
    if ( LoadConfigString("starcraft", "sound", "ON") == "OFF" )
      BW::BWDATA_DSoundDestroy();
  }

  // WMODE config option
  if ( switchToWMode && ghMainWnd )
  {
    switchToWMode = false;
    SetWMode(windowRect.right, windowRect.bottom, true);
  }

  //click the menu dialog that pops up when you win/lose a game
  BW::dialog *endDialog = BW::FindDialogGlobal("LMission");
  if ( !endDialog )
    endDialog = BW::FindDialogGlobal("WMission");
  if ( endDialog )
    endDialog->findIndex(-2)->activate();
}
Beispiel #3
0
void AutoMenuManager::onMenuFrame()
{
  static DWORD createdTimer;
  static DWORD waitJoinTimer;
  static DWORD waitSelRaceTimer;
  static DWORD waitRestartTimer;

  // Don't attempt auto-menu if we run into 50 error message boxes
  if (this->autoMapTryCount > 50)
    return;

  // Return if autoMenu is not enabled
  if (this->autoMenuMode == "" || this->autoMenuMode == "OFF")
    return;

#ifdef _DEBUG
  // Wait for a debugger if autoMenuPause is enabled, and in DEBUG
  if (this->autoMenuPause != "OFF" && !IsDebuggerPresent())
    return;
#endif

  // Get the menu mode
  int menu = BW::BWDATA::glGluesMode;

  // Declare a commonly used dialog pointer
  BW::dialog *tempDlg = nullptr;

  // Get some autoMenu properties
  bool isAutoSingle = this->autoMenuMode == "SINGLE_PLAYER";
  bool isCreating = !this->autoMenuMapPath.empty();
  bool isJoining = !this->autoMenuGameName.empty();

  // Reset raceSel flag
  if (menu != BW::GLUE_CHAT)
  {
    this->actRaceSel = false;
    this->actStartedGame = false;
  }

  // Iterate through the menus
  switch (menu)
  {
  case BW::GLUE_MAIN_MENU:    // Main menu
    if (BW::FindDialogGlobal("TitleDlg")) // skip if at title
      break;

    // Choose single or multi
    pressDialogKey(BW::FindDialogGlobal("MainMenu")->findIndex(isAutoSingle ? 3 : 4));

    // choose original or expansion (we always choose expansion)
    if (BW::FindDialogGlobal("Delete"))
      pressDialogKey(BW::FindDialogGlobal("Delete")->findIndex(7));
    break;
  case BW::GLUE_EX_CAMPAIGN:  // Campaign selection menu
  case BW::GLUE_CAMPAIGN:
    // Choose "Custom"
    pressDialogKey(BW::FindDialogGlobal("RaceSelection")->findIndex(10));
    break;
  case BW::GLUE_CREATE:       // Game creation menu
  case BW::GLUE_CREATE_MULTI:
    // Store the tick count while in this menu, and refer to it in the next
    createdTimer = GetTickCount();
    tempDlg = BW::FindDialogGlobal("Create");

    if (!this->lastMapGen.empty())
    {
      if (getFileType(this->lastMapGen) == 1)
      {
        // convert to game type
        GameType gt = GameType::getType(this->autoMenuGameType);

        // retrieve gametype dropdown
        BW::dialog *gameTypeDropdown = tempDlg->findIndex(17);
        if (gt != GameTypes::None && gt != GameTypes::Unknown && (int)gameTypeDropdown->getSelectedValue() != gt)
          gameTypeDropdown->setSelectedByValue(gt);

        // if this is single player
        if (isAutoSingle)
        {
          // Set player race
          GameImpl::_changeRace(0, GameImpl::getMenuRace(this->autoMenuRace));

          // Set enemy races
          for (unsigned int i = 1; i <= this->autoMenuEnemyCount; ++i)
            GameImpl::_changeRace(i, GameImpl::getMenuRace(this->autoMenuEnemyRace[i]));

          //close remaining slots
          for (int i = this->autoMenuEnemyCount; i < 7; ++i)
          {
            BW::dialog *slot = tempDlg->findIndex((short)(21 + i));
            if (slot->getSelectedIndex() != 0)
              slot->setSelectedIndex(0);
          }
        } // if single
      } // if map is playable

      // if we encounter an unknown error when attempting to load the map
      if (BW::FindDialogGlobal("gluPOk"))
      {
        this->chooseNewRandomMap();
        ++this->autoMapTryCount;
        pressDialogKey(BW::FindDialogGlobal("gluPOk")->findIndex(1));
      }

      pressDialogKey(tempDlg->findIndex(12));
    } // if lastmapgen
    break;
  case BW::GLUE_CONNECT:
    tempDlg = BW::FindDialogGlobal("ConnSel");

    // Press hotkey if trying to get to BNET
    // or press it after the LAN mode has been selected
    if (this->autoMenuMode == "BATTLE_NET" ||
      (tempDlg->findIndex(5)->isVisible() &&
      tempDlg->findIndex(5)->setSelectedByString(this->autoMenuLanMode)))
      pressDialogKey(tempDlg->findIndex(9));

    waitJoinTimer = 0;
    break;
  case BW::GLUE_GAME_SELECT:  // Games listing
  {
    if (waitJoinTimer == 0)
      waitJoinTimer = GetTickCount();

    tempDlg = BW::FindDialogGlobal("GameSel");
    if (!tempDlg)
      break;

    if (isJoining &&
      !tempDlg->findIndex(5)->setSelectedByString(this->autoMenuGameName) &&
      waitJoinTimer + (3000 * (BroodwarImpl.getInstanceNumber() + 1)) > GetTickCount())
      break;

    waitJoinTimer = GetTickCount();
    isHost = !(isJoining && tempDlg->findIndex(5)->setSelectedByString(this->autoMenuGameName));

    if (isCreating && isHost)
    {
      pressDialogKey(tempDlg->findIndex(15));  // Create Game
    }
    else // is joining
    {
      this->lastMapGen.clear();
      pressDialogKey(tempDlg->findIndex(13));  // OK
    }
  }
  break;
  case BW::GLUE_CHAT:
    waitJoinTimer = 0;

    if (!actRaceSel &&
      BW::FindDialogGlobal("Chat") &&
      GameImpl::_currentPlayerId() >= 0 &&
      GameImpl::_currentPlayerId() < 8 &&
      waitSelRaceTimer + 300 < GetTickCount())
    {
      waitSelRaceTimer = GetTickCount();

      // Determine the current player's race
      Race playerRace = GameImpl::getMenuRace(this->autoMenuRace);
      if (playerRace != Races::Unknown && playerRace != Races::None)
      {
        // Check if the race was selected correctly, and prevent further changing afterwords
        u8 currentRace = BW::BWDATA::Players[GameImpl::_currentPlayerId()].nRace;

        if ((currentRace == playerRace ||
          (this->autoMenuRace == "RANDOMTP" &&
          (currentRace == Races::Terran ||
          currentRace == Races::Protoss)) ||
          (this->autoMenuRace == "RANDOMTZ" &&
          (currentRace == Races::Terran ||
          currentRace == Races::Zerg)) ||
          (this->autoMenuRace == "RANDOMPZ" &&
          (currentRace == Races::Protoss ||
          currentRace == Races::Zerg))
          ))
        {
          actRaceSel = true;
        }

        // Set the race
        if (!actRaceSel)
          GameImpl::_changeRace(8, playerRace);
      }// if player race is valid
    } // if dialog "chat" exists


    if (BW::FindDialogGlobal("gluPOk"))
    {
      pressDialogKey(BW::FindDialogGlobal("gluPOk")->findIndex(1));
      actStartedGame = false;
      waitRestartTimer = GetTickCount();
    }

    // Start the game if creating and auto-menu requirements are met
    if (isCreating &&
      waitRestartTimer + 2000 < GetTickCount() &&
      !actStartedGame &&
      isHost &&
      getLobbyPlayerReadyCount() > 0 &&
      getLobbyPlayerReadyCount() == getLobbyPlayerCount() &&
      (getLobbyPlayerReadyCount() >= this->autoMenuMinPlayerCount || getLobbyOpenCount() == 0))
    {
      if (getLobbyPlayerReadyCount() >= this->autoMenuMaxPlayerCount || getLobbyOpenCount() == 0 || GetTickCount() > createdTimer + this->autoMenuWaitPlayerTime)
      {
        if (!BW::FindDialogGlobal("Chat")->findIndex(7)->isDisabled())
        {
          actStartedGame = true;
          BW::FindDialogGlobal("Chat")->findIndex(7)->activate();
        }
      } // if lobbyPlayerCount etc
    } // if isCreating etc
    break;
  case BW::GLUE_LOGIN:  // Registry/Character screen
    // Type in "BWAPI" if no characters available
    tempDlg = BW::FindDialogGlobal("gluPEdit");
    if (tempDlg)
    {
      tempDlg->findIndex(4)->setText("BWAPI");
      pressDialogKey(tempDlg->findIndex(1));
    }
    else
    {
      pressDialogKey(BW::FindDialogGlobal("Login")->findIndex(4));
    }
    break;
  case BW::GLUE_SCORE_Z_DEFEAT:
  case BW::GLUE_SCORE_Z_VICTORY:
  case BW::GLUE_SCORE_T_DEFEAT:
  case BW::GLUE_SCORE_T_VICTORY:
  case BW::GLUE_SCORE_P_DEFEAT:
  case BW::GLUE_SCORE_P_VICTORY:
    if (this->autoMenuRestartGame != "" && this->autoMenuRestartGame != "OFF")
      pressDialogKey(BW::FindDialogGlobal("End")->findIndex(7));
    break;
  case BW::GLUE_READY_T:  // Mission Briefing
  case BW::GLUE_READY_Z:
  case BW::GLUE_READY_P:
    pressDialogKey(BW::FindDialogGlobal(menu == BW::GLUE_READY_Z ? "ReadyZ" : "TerranRR")->findIndex(13));
    break;
  } // menu switch
}