void Game::Update(float dt){ m_IC->Update(dt); m_TimeRemaining = m_RoundTime - (time(nullptr) - m_StartingTime); if (m_TimeRemaining < 0){ NewRound(); } }
Bot::Bot (edict_t *bot, int skill, int personality, int team, int member) { // this function does core operation of creating bot, it's called by CreateBot (), // when bot setup completed, (this is a bot class constructor) char rejectReason[128]; int clientIndex = ENTINDEX (bot); memset (this, 0, sizeof (Bot)); pev = VARS (bot); if (bot->pvPrivateData != null) FREE_PRIVATE (bot); bot->pvPrivateData = null; bot->v.frags = 0; // create the player entity by calling MOD's player function BotControl::CallGameEntity (&bot->v); // set all info buffer keys for this bot char *buffer = GET_INFOKEYBUFFER (bot); SET_CLIENT_KEYVALUE (clientIndex, buffer, "model", ""); SET_CLIENT_KEYVALUE (clientIndex, buffer, "rate", "3500.000000"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_updaterate", "20"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_lw", "1"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_lc", "1"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "tracker", "0"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "cl_dlmax", "128"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "friends", "0"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "dm", "0"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "_ah", "0"); if (yb_tagbots.GetBool ()) SET_CLIENT_KEYVALUE (clientIndex, buffer, "*bot", "1"); SET_CLIENT_KEYVALUE (clientIndex, buffer, "_vgui_menus", "0"); memset (rejectReason, 0, sizeof (rejectReason)); // reset the reject reason template string MDLL_ClientConnect (bot, "fakeclient", FormatBuffer ("192.168.1.%d", ENTINDEX (bot) + 100), rejectReason); if (!IsNullString (rejectReason)) { AddLogEntry (true, LOG_WARNING, "Server refused '%s' connection (%s)", STRING (bot->v.netname), rejectReason); ServerCommand ("kick \"%s\"", STRING (bot->v.netname)); // kick the bot player if the server refused it bot->v.flags |= FL_KILLME; } if (IsDedicatedServer () && engine->GetDeveloperLevel () > 0) { if (engine->GetDeveloperLevel () == 2) { ServerPrint ("Server requiring authentication"); ServerPrint ("Client '%s' connected", STRING (bot->v.netname)); ServerPrint ("Adr: 127.0.0.%d:27005", ENTINDEX (bot) + 100); } ServerPrint ("Verifying and uploading resources..."); ServerPrint ("Custom resources total 0 bytes"); ServerPrint (" Decals: 0 bytes"); ServerPrint ("----------------------"); ServerPrint ("Resources to request: 0 bytes"); } MDLL_ClientPutInServer (bot); bot->v.flags = 0; bot->v.flags |= FL_FAKECLIENT | FL_CLIENT; // set this player as fakeclient // initialize all the variables for this bot... m_notStarted = true; // hasn't joined game yet m_startAction = CMENU_IDLE; m_moneyAmount = 0; m_logotypeIndex = engine->RandomInt (0, 5); // initialize msec value m_msecNum = m_msecDel = 0.0f; m_msecInterval = engine->GetTime (); m_msecVal = static_cast <uint8_t> (g_pGlobals->frametime * 1000.0f); m_msecBuiltin = engine->RandomInt (1, 4); // assign how talkative this bot will be m_sayTextBuffer.chatDelay = engine->RandomFloat (3.8f, 10.0f); m_sayTextBuffer.chatProbability = engine->RandomInt (1, 100); m_notKilled = false; m_skill = skill; m_weaponBurstMode = BURST_DISABLED; m_lastThinkTime = engine->GetTime (); m_frameInterval = engine->GetTime (); bot->v.idealpitch = bot->v.v_angle.x; bot->v.ideal_yaw = bot->v.v_angle.y; bot->v.yaw_speed = engine->RandomFloat (g_skillTab[m_skill / 20].minTurnSpeed, g_skillTab[m_skill / 20].maxTurnSpeed); bot->v.pitch_speed = engine->RandomFloat (g_skillTab[m_skill / 20].minTurnSpeed, g_skillTab[m_skill / 20].maxTurnSpeed); switch (personality) { case 1: m_personality = PERSONALITY_RUSHER; m_baseAgressionLevel = engine->RandomFloat (0.7f, 1.0f); m_baseFearLevel = engine->RandomFloat (0.0f, 0.4f); break; case 2: m_personality = PERSONALITY_CAREFUL; m_baseAgressionLevel = engine->RandomFloat (0.0f, 0.4f); m_baseFearLevel = engine->RandomFloat (0.7f, 1.0f); break; default: m_personality = PERSONALITY_NORMAL; m_baseAgressionLevel = engine->RandomFloat (0.4f, 0.7f); m_baseFearLevel = engine->RandomFloat (0.4f, 0.7f); break; } memset (&m_ammoInClip, 0, sizeof (m_ammoInClip)); memset (&m_ammo, 0, sizeof (m_ammo)); m_currentWeapon = 0; // current weapon is not assigned at start m_voicePitch = engine->RandomInt (166, 250) / 2; // assign voice pitch // copy them over to the temp level variables m_agressionLevel = m_baseAgressionLevel; m_fearLevel = m_baseFearLevel; m_nextEmotionUpdate = engine->GetTime () + 0.5f; // just to be sure m_actMessageIndex = 0; m_pushMessageIndex = 0; // assign team and class m_wantedTeam = team; m_wantedClass = member; NewRound (); }
int CGame::PlayRound() { int turn, count, last_count = 0, num_pass = 0, i, base, multiply = 1; CCard rgDiscarded[20], rgLastDiscarded[20]; bool lord_followed = false, other_followed = false; m_iCurLord = -1; while (1) { NewRound(); base = Bidding(); if (base > 0) { break; } m_rgpPlayers[0]->NoBidder(); m_rgpPlayers[1]->NoBidder(); m_rgpPlayers[2]->NoBidder(); } m_rgpPlayers[m_iCurLord]->GetKittyCards(m_rgKittyCard); m_rgpPlayers[0]->BecomeLord(RL(m_iCurLord, 0), m_rgKittyCard); m_rgpPlayers[1]->BecomeLord(RL(m_iCurLord, 1), m_rgKittyCard); m_rgpPlayers[2]->BecomeLord(RL(m_iCurLord, 2), m_rgKittyCard); turn = m_iCurLord; rgLastDiscarded[0] = 255; while (1) { count = -1; m_rgpPlayers[0]->UpdateStatus(base, multiply); m_rgpPlayers[1]->UpdateStatus(base, multiply); m_rgpPlayers[2]->UpdateStatus(base, multiply); m_rgpPlayers[0]->Turn(RL(turn, 0)); m_rgpPlayers[1]->Turn(RL(turn, 1)); m_rgpPlayers[2]->Turn(RL(turn, 2)); while (count < 0) { count = m_rgpPlayers[turn]->Discard(rgDiscarded, !last_count); CCard::Sort(rgDiscarded, count); if (count < 20) { rgDiscarded[count] = 255; } if (!last_count) { // first hand i = GetDiscardType(rgDiscarded).type; if (i == DT_INVALID) { m_rgpPlayers[turn]->InvalidDiscard(); count = -1; } else { m_rgpPlayers[turn]->DoDiscard(rgDiscarded, count); if (i >= DT_QUAD) { multiply *= 2; } for (i = 0; i < count; i++) { rgLastDiscarded[i] = rgDiscarded[i]; } if (i < 20) { rgLastDiscarded[i] = 255; } last_count = count; } } else if (count != 0) { // following a card discardhand_t dh; if (!CompareDiscard(rgLastDiscarded, rgDiscarded, NULL, &dh)) { m_rgpPlayers[turn]->InvalidDiscard(); count = -1; } else { m_rgpPlayers[turn]->DoDiscard(rgDiscarded, count); if (dh.type >= DT_QUAD) { multiply *= 2; } for (i = 0; i < count; i++) { rgLastDiscarded[i] = rgDiscarded[i]; } if (i < 20) { rgLastDiscarded[i] = 255; } last_count = count; num_pass = 0; // clear the counter of passes if (turn == m_iCurLord) { lord_followed = true; } else { other_followed = true; } } } else { // pass num_pass++; if (num_pass >= 2) { // 2 players passed num_pass = 0; rgLastDiscarded[0] = 255; last_count = 0; // if the next player is the lord if (((turn > 0) ? (turn - 1) : 2) == m_iCurLord) { lord_followed = true; } } } } #ifdef _DEBUG m_rgpPlayers[0]->PlayerDiscarded(RL(turn, 0), rgDiscarded, m_rgpPlayers[turn]->Hand(), count, m_rgpPlayers[turn]->NumHandCard()); m_rgpPlayers[1]->PlayerDiscarded(RL(turn, 1), rgDiscarded, m_rgpPlayers[turn]->Hand(), count, m_rgpPlayers[turn]->NumHandCard()); m_rgpPlayers[2]->PlayerDiscarded(RL(turn, 2), rgDiscarded, m_rgpPlayers[turn]->Hand(), count, m_rgpPlayers[turn]->NumHandCard()); #else m_rgpPlayers[0]->PlayerDiscarded(RL(turn, 0), rgDiscarded, turn == 0 ? m_rgpPlayers[turn]->Hand() : NULL, count, m_rgpPlayers[turn]->NumHandCard()); m_rgpPlayers[1]->PlayerDiscarded(RL(turn, 1), rgDiscarded, turn == 1 ? m_rgpPlayers[turn]->Hand() : NULL, count, m_rgpPlayers[turn]->NumHandCard()); m_rgpPlayers[2]->PlayerDiscarded(RL(turn, 2), rgDiscarded, turn == 2 ? m_rgpPlayers[turn]->Hand() : NULL, count, m_rgpPlayers[turn]->NumHandCard()); #endif if (m_rgpPlayers[turn]->NumHandCard() <= 0) { // this player won the round break; } turn--; if (turn < 0) { turn = 2; } } if (turn == m_iCurLord) { multiply *= other_followed ? 1 : 2; } else { multiply *= lord_followed ? 1 : 2; } m_rgpPlayers[0]->UpdateStatus(base, multiply); m_rgpPlayers[1]->UpdateStatus(base, multiply); m_rgpPlayers[2]->UpdateStatus(base, multiply); m_iPoints = base * multiply; return turn; }
void MainWindow::DoWork() { if(CurrentStatus == 0) { if(doorList[UserSelectedDoor].IsWinner()) { CurrentStatus = 3; UpdateStatus(); Correct++; Result++; ui->labelCorrect->setText(QString::number(Correct)); ui->labelResult->setText(QString::number(Result)); for(int i = 0; i < doorList.count(); i++) { if(doorList[i].IsWinner()) { if(i == 0) { ui->pushButtonDoorOne->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaMoney.jpg); position: relative}"); // ui->pushButtonDoorOne->setChecked(true); } else if(i == 1) { ui->pushButtonDoorTwo->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaMoney.jpg); position: relative}"); // ui->pushButtonDoorTwo->setChecked(true); } else if(i == 2) { ui->pushButtonDoorThree->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaMoney.jpg); position: relative}"); // ui->pushButtonDoorThree->setChecked(true); } // ui->pushButtonDoorThree->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaMoney.jpg); position: relative}"); } else { if(i == 0) { ui->pushButtonDoorOne->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); // ui->pushButtonDoorOne->setChecked(true); } else if(i == 1) { ui->pushButtonDoorTwo->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); // ui->pushButtonDoorTwo->setChecked(true); } else if(i == 2) { ui->pushButtonDoorThree->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); // ui->pushButtonDoorThree->setChecked(true); } // ui->pushButtonDoorThree->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); } } ui->pushButtonDoorOne->setEnabled(false); ui->pushButtonDoorTwo->setEnabled(false); ui->pushButtonDoorThree->setEnabled(false); QTimer::singleShot(2000, this, SLOT(NewRound())); } else { CurrentStatus = 1; UpdateStatus(); for(int i = 0; i < doorList.count(); i++) { if(!doorList[i].IsWinner() && i != UserSelectedDoor) { qDebug() << "Computer opens door number " << i; // Computer open door, the one not clicked by user, and with no reward. CurrentStatus = 2; UpdateStatus(); if(i == 0) { ui->pushButtonDoorOne->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); ui->pushButtonDoorOne->setChecked(true); ui->pushButtonDoorOne->setEnabled(false); } else if(i == 1) { ui->pushButtonDoorTwo->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); ui->pushButtonDoorTwo->setChecked(true); ui->pushButtonDoorTwo->setEnabled(false); } else if(i == 2) { ui->pushButtonDoorThree->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); ui->pushButtonDoorThree->setChecked(true); ui->pushButtonDoorThree->setEnabled(false); } } } } } else if(CurrentStatus == 2) { if(doorList[UserSelectedDoor].IsWinner()) { CurrentStatus = 3; UpdateStatus(); Correct++; Result++; ui->labelCorrect->setText(QString::number(Correct)); ui->labelResult->setText(QString::number(Result)); } else { Wrong++; Result--; CurrentStatus = 4; UpdateStatus(); ui->labelWrong->setText(QString::number(Wrong)); ui->labelResult->setText(QString::number(Result)); } qDebug() << "Current Status " << CurrentStatus; for(int i = 0; i < doorList.count(); i++) { if(doorList[i].IsWinner()) { if(i == 0) { ui->pushButtonDoorOne->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaMoney.jpg); position: relative}"); // ui->pushButtonDoorOne->setChecked(true); } else if(i == 1) { ui->pushButtonDoorTwo->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaMoney.jpg); position: relative}"); // ui->pushButtonDoorTwo->setChecked(true); } else if(i == 2) { ui->pushButtonDoorThree->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaMoney.jpg); position: relative}"); // ui->pushButtonDoorThree->setChecked(true); } } else { if(i == 0) { ui->pushButtonDoorOne->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); } else if(i == 1) { ui->pushButtonDoorTwo->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); } else if(i == 2) { ui->pushButtonDoorThree->setStyleSheet("QPushButton{border-image:url(:/Slike/VrataOdprtaPoop.jpg); position: relative}"); } } } CurrentStatus = 0; ui->pushButtonDoorOne->setEnabled(false); ui->pushButtonDoorTwo->setEnabled(false); ui->pushButtonDoorThree->setEnabled(false); QTimer::singleShot(2000, this, SLOT(NewRound())); } }