/* Procedure pour afficher les boutons et popup * @param SDL_Surface* window * Surface de la fenetre * @param S_GameState gameState * Etat du jeu */ void DisplayBoardOverlays(SDL_Surface* window, S_GameState gameState) { switch (gameState.currentStage) { case WAITING_FIRST_ROLL: DisplayButton(window, CENTER_X, CENTER_Y, "Lancer", gameState.selected == BUTTON1); break; case WAITING_ROLL_DBL: // On affiche les boutons que si le joueur est humain if (IsHuman(&gameState, 1)) { DisplayButton(window, (gameState.currentPlayer == EPlayer1) ? CENTER_LEFT : CENTER_RIGHT, CENTER_Y - 20, "Doubler", gameState.selected == BUTTON1); DisplayButton(window, (gameState.currentPlayer == EPlayer1) ? CENTER_LEFT : CENTER_RIGHT, CENTER_Y + 20, "Lancer", gameState.selected == BUTTON2); } break; case WAITING_ROLL: // On affiche les boutons que si le joueur est humain if (IsHuman(&gameState, 1)) { DisplayButton(window, (gameState.currentPlayer == EPlayer1) ? CENTER_LEFT : CENTER_RIGHT, CENTER_Y, "Lancer", gameState.selected == BUTTON1); } break; case FIRST_ROLL_POPUP: DisplayDice(window, gameState); // On affiche la popup que si un humain joue if (gameState.gameConfig.mode != AI_AI) { if (gameState.currentPlayer == EPlayer1) DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer1, "commence."); else DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer2, "commence."); DisplayButton(window, CENTER_X, 320, "OK", gameState.selected == BUTTON1); } break; case SELECT_ZONE_DST: DisplayNumbers(window, gameState); DisplayDice(window, gameState); if (gameState.gameConfig.option && gameState.gameConfig.mode != AI_AI) DisplayHelp(window, gameState); break; case PASS_POPUP: DisplayDice(window, gameState); // On affiche la popup que si le joueur est humain if (IsHuman(&gameState, 1)) { if (gameState.currentPlayer == EPlayer1) DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer1, "passe son tour."); else DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer2, "passe son tour."); DisplayButton(window, CENTER_X, 320, "OK", gameState.selected == BUTTON1); } break; case DOUBLE_POPUP: // On affiche la popup que si le joueur adverse est humain if (IsHuman(&gameState, 0)) { if (gameState.currentPlayer == EPlayer1) DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer1, "veut doubler."); else DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer2, "veut doubler."); DisplayButton(window, CENTER_X - 60, 320, "Accepter", gameState.selected == BUTTON1); DisplayButton(window, CENTER_X + 60, 320, "Refuser", gameState.selected == BUTTON2); } break; case FINISH_GAME_POPUP: DisplayDice(window, gameState); // On affiche la popup que si un joueur est humain if (gameState.gameConfig.mode != AI_AI) { if (gameState.currentPlayer == EPlayer1) DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer1, "a gagné la manche."); else DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer2, "a gagné la manche."); DisplayButton(window, CENTER_X, 320, "OK", gameState.selected == BUTTON1); } break; case FINISH_MATCH_POPUP: DisplayDice(window, gameState); if (gameState.currentPlayer == EPlayer1) DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer1, "a gagné le match."); else DisplayPopup(window, 3, "Le joueur", gameState.gameConfig.namePlayer2, "a gagné le match."); DisplayButton(window, CENTER_X, 320, "Menu", gameState.selected == BUTTON1); break; default: DisplayNumbers(window, gameState); DisplayDice(window, gameState); break; } }
void CChar::Use_CarveCorpse( CItemCorpse * pCorpse ) { ADDTOCALLSTACK("CChar::Use_CarveCorpse"); CREID_TYPE CorpseID = pCorpse->m_itCorpse.m_BaseID; CCharBase *pCorpseDef = CCharBase::FindCharBase(CorpseID); if ( !pCorpseDef || pCorpse->m_itCorpse.m_carved ) { SysMessageDefault(DEFMSG_CARVE_CORPSE_NOTHING); return; } CChar *pChar = pCorpse->m_uidLink.CharFind(); CPointMap pnt = pCorpse->GetTopLevelObj()->GetTopPoint(); UpdateAnimate(ANIM_BOW); if ( pCorpse->m_TagDefs.GetKeyNum("BLOOD", true) ) { CItem *pBlood = CItem::CreateBase(ITEMID_BLOOD4); ASSERT(pBlood); pBlood->SetHue(pCorpseDef->m_wBloodHue); pBlood->MoveToDecay(pnt, 5 * TICK_PER_SEC); } size_t iItems = 0; for ( size_t i = 0; i < pCorpseDef->m_BaseResources.GetCount(); i++ ) { long long iQty = pCorpseDef->m_BaseResources[i].GetResQty(); RESOURCE_ID rid = pCorpseDef->m_BaseResources[i].GetResourceID(); if ( rid.GetResType() != RES_ITEMDEF ) continue; ITEMID_TYPE id = static_cast<ITEMID_TYPE>(rid.GetResIndex()); if ( id == ITEMID_NOTHING ) break; iItems++; CItem *pPart = CItem::CreateTemplate(id, NULL, this); ASSERT(pPart); switch ( pPart->GetType() ) { case IT_FOOD: case IT_FOOD_RAW: case IT_MEAT_RAW: SysMessageDefault(DEFMSG_CARVE_CORPSE_MEAT); //pPart->m_itFood.m_MeatType = CorpseID; break; case IT_HIDE: SysMessageDefault(DEFMSG_CARVE_CORPSE_HIDES); //pPart->m_itSkin.m_creid = CorpseID; if ( (g_Cfg.m_iRacialFlags & RACIALF_HUMAN_WORKHORSE) && IsHuman() ) // humans always find 10% bonus when gathering hides, ores and logs (Workhorse racial trait) iQty = iQty * 110 / 100; break; case IT_FEATHER: SysMessageDefault(DEFMSG_CARVE_CORPSE_FEATHERS); //pPart->m_itSkin.m_creid = CorpseID; break; case IT_WOOL: SysMessageDefault(DEFMSG_CARVE_CORPSE_WOOL); //pPart->m_itSkin.m_creid = CorpseID; break; /*case IT_DRAGON_SCALE: // TO-DO (typedef IT_DRAGON_SCALE doesn't exist yet) SysMessageDefault(DEFMSG_CARVE_CORPSE_SCALES); //pPart->m_itSkin.m_creid = CorpseID; break;*/ default: break; } if ( iQty > 1 ) pPart->SetAmount(static_cast<unsigned int>(iQty)); if ( pChar && pChar->m_pPlayer ) { TCHAR *pszMsg = Str_GetTemp(); sprintf(pszMsg, g_Cfg.GetDefaultMsg(DEFMSG_CORPSE_NAME), pPart->GetName(), pChar->GetName()); pPart->SetName(pszMsg); pPart->m_uidLink = pChar->GetUID(); pPart->MoveToDecay(pnt, pPart->GetDecayTime()); continue; } pCorpse->ContentAdd(pPart); } if ( iItems < 1 ) SysMessageDefault(DEFMSG_CARVE_CORPSE_NOTHING); CheckCorpseCrime(pCorpse, false, false); pCorpse->m_itCorpse.m_carved = 1; // mark as been carved pCorpse->m_itCorpse.m_uidKiller = GetUID(); // by you if ( pChar && pChar->m_pPlayer ) pCorpse->SetTimeout(0); // reset corpse timer to make it turn bones }
/* Procedure de gestion des actions des IA * @param S_GameState* gameState * Etat du jeu */ void AI_EventsBoard(S_GameState* gameState) { switch (gameState->currentStage) { case WAITING_ROLL_DBL: if (!IsHuman(gameState, 1)) { // On demande a l'IA si elle veut doubler ou pas int answer = 0; SGameState AI_gameState; CreateAIGameState(&AI_gameState, gameState); if (gameState->currentPlayer == EPlayer1) answer = gameState->gameConfig.aiFunctions[0].AI_DoubleStack(&AI_gameState); else answer = gameState->gameConfig.aiFunctions[1].AI_DoubleStack(&AI_gameState); // L'IA double if (answer) gameState->currentStage = DOUBLE_POPUP; else { RollDice(gameState); if (IsPossibleMove(gameState)) gameState->currentStage = SELECT_ZONE_SRC; else gameState->currentStage = PASS_POPUP; } } break; case WAITING_ROLL: // On gere le bouton que si le joueur est humain if (!IsHuman(gameState, 1)) { RollDice(gameState); if (IsPossibleMove(gameState)) gameState->currentStage = SELECT_ZONE_SRC; else gameState->currentStage = PASS_POPUP; } break; case DOUBLE_POPUP: if (!IsHuman(gameState, 0)) { // On demande a l'IA si elle accepte ou refuse le double int answer = 0; SGameState AI_gameState; CreateAIGameState(&AI_gameState, gameState); if (gameState->currentPlayer == EPlayer1) answer = gameState->gameConfig.aiFunctions[1].AI_TakeDouble(&AI_gameState); else answer = gameState->gameConfig.aiFunctions[0].AI_TakeDouble(&AI_gameState); // l'IA accepte le double if (answer) { gameState->stake *= 2; if (gameState->currentPlayer == EPlayer1) gameState->cubeOwner = EPlayer2; else gameState->cubeOwner = EPlayer1; gameState->currentStage = WAITING_ROLL; } // l'IA refuse le double else { // Le joueur courant gagne la partie if (gameState->currentPlayer == EPlayer1) gameState->scoreP1 += gameState->stake; else gameState->scoreP2 += gameState->stake; gameState->currentStage = FINISH_GAME_POPUP; } } break; case FIRST_ROLL_POPUP: // On passe la popup if (gameState->gameConfig.mode == AI_AI) { if (IsPossibleMove(gameState)) gameState->currentStage = SELECT_ZONE_SRC; else gameState->currentStage = PASS_POPUP; } break; case PASS_POPUP: // On passe la popup if (!IsHuman(gameState, 1)) { if (gameState->currentPlayer == EPlayer1) gameState->currentPlayer = EPlayer2; else gameState->currentPlayer = EPlayer1; if (gameState->cubeOwner == gameState->currentPlayer || gameState->stake == 1) gameState->currentStage = WAITING_ROLL_DBL; else gameState->currentStage = WAITING_ROLL; } break; case FINISH_GAME_POPUP: // On passe la popup if (gameState->gameConfig.mode == AI_AI) { // On desalloue les IA gameState->gameConfig.aiFunctions[0].AI_EndGame(); gameState->gameConfig.aiFunctions[1].AI_EndGame(); if ((gameState->currentPlayer == EPlayer1 && gameState->scoreP1 >= gameState->gameConfig.points) || (gameState->currentPlayer == EPlayer2 && gameState->scoreP2 >= gameState->gameConfig.points)) gameState->currentStage = FINISH_MATCH_POPUP; else { // On reinitialise les IA gameState->gameConfig.aiFunctions[0].AI_StartGame(); gameState->gameConfig.aiFunctions[1].AI_StartGame(); // Remise a zero du plateau InitGameState(gameState, gameState->gameConfig); } } break; case SELECT_ZONE_SRC: if (!IsHuman(gameState, 1)) { int done = 0; int player = (gameState->currentPlayer == EPlayer1) ? 0 : 1; int error = 0; while (gameState->aiErrors[player] <= 3 && !done) { SGameState AI_gameState; CreateAIGameState(&AI_gameState, gameState); SMove moves[4]; int i; for (i=0; i<4; i++) { moves[i].src_point = EPos_nopos; moves[i].dest_point = EPos_nopos; } if (gameState->currentPlayer == EPlayer1) gameState->gameConfig.aiFunctions[0].AI_MakeDecision(&AI_gameState, moves, error != 0); else gameState->gameConfig.aiFunctions[1].AI_MakeDecision(&AI_gameState, moves, error != 0); if (IsValidAIMoves(*gameState, moves)) { // On effectue les mouvements for (i=0; i<4; i++) { if (IsPossibleMove(gameState)) { if (moves[i].src_point != EPos_nopos && moves[i].dest_point != EPos_nopos) { int src = ConvertAIZone(gameState, moves[i].src_point); int dest = ConvertAIZone(gameState, moves[i].dest_point); gameState->currentZone = src; DoMove(dest, gameState); done = 1; gameState->refresh = 1; } } } } else { fprintf(stderr, "Mouvement incorrect de l'IA (joueur %i)\n", gameState->currentPlayer + 1); gameState->aiErrors[player]++; error++; gameState->refresh = 1; if (gameState->aiErrors[player] > 3) { // Le joueur courant gagne la partie if (gameState->currentPlayer == EPlayer1) gameState->scoreP2 += gameState->stake; else gameState->scoreP1 += gameState->stake; gameState->currentStage = FINISH_GAME_POPUP; } } } } break; default: break; } }
bool ribi::con3::ConnectThreeWidget::IsComputerTurn() const noexcept { return !IsHuman(m_game.GetActivePlayer()); }
/* Fonction de gestion des evenements du plateau * @param SDL_Event* event * Evenements de la fenetre * @param S_GameState* gameState * Etat du jeu * @return E_BoardSelected * Eventuel bouton clique */ E_BoardSelected EventsBoard(SDL_Event* event, S_GameState* gameState) { E_BoardSelected clicked = NONE_BOARD; if (gameState->gameConfig.mode == HUMAN_HUMAN) SDL_WaitEvent(event); // On attend l'evenement else SDL_PollEvent(event); // Defilement automatique int zone = -1; int bx; if (event->type == SDL_QUIT) clicked = QUIT_BOARD; switch (gameState->currentStage) { case WAITING_FIRST_ROLL: switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "Lancer" if (ClickRect(event, 293, 230, 100, 30)) gameState->selected = BUTTON1; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "Lancer" if (ClickRect(event, 293, 230, 100, 30)) RollDice(gameState); break; } break; case WAITING_ROLL_DBL: // On gere les boutons que si le joueur est humain if (IsHuman(gameState, 1)) { bx = (gameState->currentPlayer == EPlayer1) ? 122 : 464; switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "Doubler" if (ClickRect(event, bx, 210, 100, 30)) gameState->selected = BUTTON1; // Bouton "Lancer" if (ClickRect(event, bx, 250, 100, 30)) gameState->selected = BUTTON2; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "Doubler" if (ClickRect(event, bx, 210, 100, 30)) gameState->currentStage = DOUBLE_POPUP; // Bouton "Lancer" if (ClickRect(event, bx, 250, 100, 30)) { RollDice(gameState); if (IsPossibleMove(gameState)) gameState->currentStage = SELECT_ZONE_SRC; else gameState->currentStage = PASS_POPUP; } break; } } break; case WAITING_ROLL: // On gere le bouton que si le joueur est humain if (IsHuman(gameState, 1)) { bx = (gameState->currentPlayer == EPlayer1) ? 122 : 464; switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "Lancer" if (ClickRect(event, bx, 230, 100, 30)) gameState->selected = BUTTON1; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "Lancer" if (ClickRect(event, bx, 230, 100, 30)) { RollDice(gameState); if (IsPossibleMove(gameState)) gameState->currentStage = SELECT_ZONE_SRC; else gameState->currentStage = PASS_POPUP; } break; } } break; case DOUBLE_POPUP: // On gere la popup que si l'adversaire est humain if (IsHuman(gameState, 0)) { switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "Accepter" if (ClickRect(event, 234, 305, 100, 30)) gameState->selected = BUTTON1; // Bouton "Refuser" if (ClickRect(event, 354, 305, 100, 30)) gameState->selected = BUTTON2; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "Accepter" if (ClickRect(event, 234, 305, 100, 30)) { gameState->stake *= 2; if (gameState->currentPlayer == EPlayer1) gameState->cubeOwner = EPlayer2; else gameState->cubeOwner = EPlayer1; gameState->currentStage = WAITING_ROLL; } // Bouton "Refuser" if (ClickRect(event, 354, 305, 100, 30)) { // Le joueur courant gagne la partie if (gameState->currentPlayer == EPlayer1) gameState->scoreP1 += gameState->stake; else gameState->scoreP2 += gameState->stake; gameState->currentStage = FINISH_GAME_POPUP; } break; } } break; case FIRST_ROLL_POPUP: // On gere la popup que si un humain joue if (gameState->gameConfig.mode != AI_AI) { switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) gameState->selected = BUTTON1; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) { if (IsPossibleMove(gameState)) gameState->currentStage = SELECT_ZONE_SRC; else gameState->currentStage = PASS_POPUP; } break; } } break; case PASS_POPUP: // On gere la popup que si le joueur courant est humain if (IsHuman(gameState, 1)) { switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) gameState->selected = BUTTON1; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) { if (gameState->currentPlayer == EPlayer1) gameState->currentPlayer = EPlayer2; else gameState->currentPlayer = EPlayer1; if (gameState->cubeOwner == gameState->currentPlayer || gameState->stake == 1) gameState->currentStage = WAITING_ROLL_DBL; else gameState->currentStage = WAITING_ROLL; } break; } } break; case FINISH_GAME_POPUP: // On gere la popup que si un joueur est humain if (gameState->gameConfig.mode != AI_AI) { switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) gameState->selected = BUTTON1; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) { // On desalloue les IA if (gameState->gameConfig.mode == HUMAN_AI) gameState->gameConfig.aiFunctions[1].AI_EndGame(); // Fin du match if ((gameState->currentPlayer == EPlayer1 && gameState->scoreP1 >= gameState->gameConfig.points) || (gameState->currentPlayer == EPlayer2 && gameState->scoreP2 >= gameState->gameConfig.points)) gameState->currentStage = FINISH_MATCH_POPUP; else { // On reinitialise les IA pour une nouvelle manche if (gameState->gameConfig.mode == HUMAN_AI) gameState->gameConfig.aiFunctions[1].AI_StartGame(); // Remise a zero du plateau InitGameState(gameState, gameState->gameConfig); } } break; } } break; case FINISH_MATCH_POPUP: switch(event->type) { case SDL_MOUSEBUTTONDOWN: // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) gameState->selected = BUTTON1; break; case SDL_MOUSEBUTTONUP: gameState->selected = NONE_BOARD; // Bouton "OK" if (ClickRect(event, 293, 305, 100, 30)) { // On ecrit dans le fichier des scores FILE* file = fopen("score.txt", "a"); fprintf(file, "%s : %d\n", gameState->gameConfig.namePlayer1, gameState->scoreP1); fprintf(file, "%s : %d\n", gameState->gameConfig.namePlayer2, gameState->scoreP2); fprintf(file, "--------------------\n"); fclose(file); // On revient au menu clicked = MENU_BOARD; } break; } break; case SELECT_ZONE_SRC: // On gere le deplacement que si le joueur courant est humain if (IsHuman(gameState, 1)) { switch(event->type) { case SDL_MOUSEBUTTONUP: // Selection d'une zone source zone = ClickZone(event); if (IsValidSrc(zone, gameState)) { gameState->currentZone = zone; gameState->currentStage = SELECT_ZONE_DST; } break; } } break; case SELECT_ZONE_DST: // On gere le deplacement que si le joueur courant est humain if (IsHuman(gameState, 1)) { switch(event->type) { case SDL_MOUSEBUTTONUP: // Selection d'une zone source zone = ClickZone(event); if (IsValidDst(zone, gameState)) DoMove(zone, gameState); else if (IsValidSrc(zone, gameState)) gameState->currentZone = zone; else { gameState->currentZone = -1; gameState->currentStage = SELECT_ZONE_SRC; } break; } } break; default: break; } return clicked; }