int ReplayMode::ReplayThread(void* param) { ReplayHeader rh = cur_replay.pheader; mainGame->dInfo.isFirst = true; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); set_card_reader((card_reader)DataManager::CardReader); set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; mainGame->dInfo.strTurn[0] = 0; int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, 0); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, 0); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, 0); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, 0); mainGame->dField.Initial(1, main, extra); start_duel(pduel, opt); mainGame->dInfo.isStarted = true; mainGame->dInfo.isReplay = true; char engineBuffer[0x1000]; is_continuing = true; exit_pending = false; int len = 0, flag = 0; while (is_continuing && !exit_pending) { int result = process(pduel); len = result & 0xffff; flag = result >> 16; if (len > 0) { get_message(pduel, (byte*)engineBuffer); is_continuing = ReplayAnalyze(engineBuffer, len); } } end_duel(pduel); if(!is_closing) { mainGame->stMessage->setText(dataManager.GetSysString(1501)); mainGame->actionSignal.Reset(); mainGame->PopupElement(mainGame->wMessage); mainGame->actionSignal.Wait(); mainGame->dInfo.isStarted = false; mainGame->dInfo.isReplay = false; mainGame->CloseDuelWindow(); mainGame->ClearTextures(); mainGame->ShowElement(mainGame->wReplay); mainGame->device->setEventReceiver(&mainGame->menuHandler); } return 0; }
int SingleMode::SinglePlayThread(void* param) { const wchar_t* name = mainGame->lstSinglePlayList->getListItem(mainGame->lstSinglePlayList->getSelected()); wchar_t fname[256]; myswprintf(fname, L"./single/%ls", name); char fname2[256]; size_t slen = BufferIO::EncodeUTF8(fname, fname2); mtrandom rnd; time_t seed = time(0); rnd.reset(seed); set_card_reader((card_reader)DataManager::CardReader); set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); set_player_info(pduel, 0, 8000, 5, 1); set_player_info(pduel, 1, 8000, 5, 1); mainGame->dInfo.lp[0] = 8000; mainGame->dInfo.lp[1] = 8000; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); BufferIO::CopyWStr(mainGame->ebNickName->getText(), mainGame->dInfo.hostname, 20); mainGame->dInfo.clientname[0] = 0; mainGame->dInfo.turn = 0; mainGame->dInfo.strTurn[0] = 0; if(!preload_script(pduel, fname2, slen)) { end_duel(pduel); return 0; } mainGame->gMutex.Lock(); mainGame->HideElement(mainGame->wSinglePlay); mainGame->wCardImg->setVisible(true); mainGame->wInfos->setVisible(true); mainGame->btnLeaveGame->setVisible(true); mainGame->btnLeaveGame->setText(dataManager.GetSysString(1210)); mainGame->stName->setText(L""); mainGame->stInfo->setText(L""); mainGame->stDataInfo->setText(L""); mainGame->stText->setText(L""); mainGame->scrCardText->setVisible(false); mainGame->wPhase->setVisible(true); mainGame->dField.panel = 0; mainGame->dField.hovered_card = 0; mainGame->dField.clicked_card = 0; mainGame->dField.Clear(); mainGame->dInfo.isFirst = true; mainGame->dInfo.isStarted = true; mainGame->dInfo.isSingleMode = true; mainGame->device->setEventReceiver(&mainGame->dField); mainGame->gMutex.Unlock(); start_duel(pduel, 0); char engineBuffer[0x1000]; is_closing = false; is_continuing = true; int len = 0; while (is_continuing) { int result = process(pduel); len = result & 0xffff; /* int flag = result >> 16; */ if (len > 0) { get_message(pduel, (byte*)engineBuffer); is_continuing = SinglePlayAnalyze(engineBuffer, len); } } end_duel(pduel); if(!is_closing) { mainGame->gMutex.Lock(); mainGame->dInfo.isStarted = false; mainGame->dInfo.isSingleMode = false; mainGame->gMutex.Unlock(); mainGame->closeDoneSignal.Reset(); mainGame->closeSignal.Set(); mainGame->closeDoneSignal.Wait(); mainGame->gMutex.Lock(); mainGame->ShowElement(mainGame->wSinglePlay); mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->gMutex.Unlock(); } return 0; }
bool ReplayMode::StartDuel() { const ReplayHeader& rh = cur_replay.pheader; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if(mainGame->dInfo.isTag) { cur_replay.ReadName(mainGame->dInfo.hostname); cur_replay.ReadName(mainGame->dInfo.hostname_tag); cur_replay.ReadName(mainGame->dInfo.clientname_tag); cur_replay.ReadName(mainGame->dInfo.clientname); } else { cur_replay.ReadName(mainGame->dInfo.hostname); cur_replay.ReadName(mainGame->dInfo.clientname); } pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); int duel_rule = opt >> 16; mainGame->dInfo.duel_rule = duel_rule; set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if(!mainGame->dInfo.isSingleMode) { if(!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } } else { char filename[256]; size_t slen = cur_replay.ReadInt16(); cur_replay.ReadData(filename, slen); filename[slen] = 0; if(!preload_script(pduel, filename, 0)) { return false; } } start_duel(pduel, opt); return true; }
bool ReplayMode::StartDuel() { const ReplayHeader& rh = cur_replay.pheader; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if (mainGame->dInfo.isRelay) { cur_replay.ReadName(mainGame->dInfo.hostname[0]); cur_replay.ReadName(mainGame->dInfo.hostname[1]); cur_replay.ReadName(mainGame->dInfo.hostname[2]); cur_replay.ReadName(mainGame->dInfo.clientname[0]); cur_replay.ReadName(mainGame->dInfo.clientname[1]); cur_replay.ReadName(mainGame->dInfo.clientname[2]); } else if (mainGame->dInfo.isTag) { cur_replay.ReadName(mainGame->dInfo.hostname[0]); cur_replay.ReadName(mainGame->dInfo.hostname[1]); cur_replay.ReadName(mainGame->dInfo.clientname[1]); cur_replay.ReadName(mainGame->dInfo.clientname[0]); } else { cur_replay.ReadName(mainGame->dInfo.hostname[0]); cur_replay.ReadName(mainGame->dInfo.clientname[0]); } pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); int duel_rule = opt >> 16; int rule = opt >> 16; //backwards compatibility with master rule replays if (rule) switch (rule) { case 1: { opt |= MASTER_RULE_1; break; } case 2: { opt |= MASTER_RULE_2; break; } case 3: { opt |= MASTER_RULE_3; break; } case 4: { opt |= MASTER_RULE_4; break; } } //pre mr4 replay compatibility if (opt & DUEL_OBSOLETE_RULING) { opt &= ~DUEL_OBSOLETE_RULING; opt |= MASTER_RULE_1; } else if (!(opt & 0xff80)) opt |= MASTER_RULE_3; mainGame->dInfo.duel_field = 2; if ((opt & DUEL_PZONE) && (opt & DUEL_SEPARATE_PZONE) && (opt & DUEL_EMZONE)) mainGame->dInfo.duel_field = 5; else if (opt & DUEL_EMZONE) mainGame->dInfo.duel_field = 4; else if (opt & DUEL_PZONE) mainGame->dInfo.duel_field = 3; mainGame->dInfo.extraval = (opt & SPEED_DUEL) ? 1 : 0; mainGame->SetPhaseButtons(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; mainGame->dInfo.startlp = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if (!mainGame->dInfo.isSingleMode) { if (!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for (int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for (int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } } else { char filename[256]; size_t slen = cur_replay.ReadInt16(); cur_replay.ReadData(filename, slen); filename[slen] = 0; if (!preload_script(pduel, filename, slen)) { return false; } } start_duel(pduel, opt); return true; }
int ReplayMode::ReplayThread(void* param) { const ReplayHeader& rh = cur_replay.pheader; mainGame->dInfo.isFirst = true; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if(rh.flag & REPLAY_TAG) { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.hostname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); mainGame->dInfo.isTag = true; mainGame->dInfo.tag_player[0] = false; mainGame->dInfo.tag_player[1] = false; } else { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); } set_script_reader(default_script_reader); set_card_reader((card_reader)DataManager::CardReader); set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if(!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } start_duel(pduel, opt); ReplayRefreshDeck(0); ReplayRefreshDeck(1); ReplayRefreshExtra(0); ReplayRefreshExtra(1); mainGame->dInfo.isStarted = true; mainGame->dInfo.isReplay = true; char engineBuffer[0x1000]; is_continuing = true; exit_pending = false; current_step = 0; skip_step = 0; if(skip_turn < 0) skip_turn = 0; if(skip_turn) { mainGame->dInfo.isReplaySkiping = true; mainGame->gMutex.Lock(); } else mainGame->dInfo.isReplaySkiping = false; int len = 0; while (is_continuing && !exit_pending) { int result = process(pduel); len = result & 0xffff; /*int flag = result >> 16;*/ if (len > 0) { get_message(pduel, (byte*)engineBuffer); is_continuing = ReplayAnalyze(engineBuffer, len); } } if(mainGame->dInfo.isReplaySkiping) { mainGame->dInfo.isReplaySkiping = false; mainGame->dField.RefreshAllCards(); mainGame->gMutex.Unlock(); } end_duel(pduel); if(!is_closing) { mainGame->actionSignal.Reset(); mainGame->gMutex.Lock(); mainGame->stMessage->setText(dataManager.GetSysString(1501)); if(mainGame->wCardSelect->isVisible()) mainGame->HideElement(mainGame->wCardSelect); mainGame->PopupElement(mainGame->wMessage); mainGame->gMutex.Unlock(); mainGame->actionSignal.Wait(); mainGame->gMutex.Lock(); mainGame->dInfo.isStarted = false; mainGame->dInfo.isReplay = false; mainGame->gMutex.Unlock(); mainGame->closeDoneSignal.Reset(); mainGame->closeSignal.Set(); mainGame->closeDoneSignal.Wait(); mainGame->gMutex.Lock(); mainGame->ShowElement(mainGame->wReplay); mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->gMutex.Unlock(); if(exit_on_return) mainGame->device->closeDevice(); } return 0; }
void ReplayMode::Restart(bool refresh) { end_duel(pduel); mainGame->dInfo.isStarted = false; mainGame->dField.panel = 0; mainGame->dField.hovered_card = 0; mainGame->dField.clicked_card = 0; mainGame->dField.Clear(); //mainGame->device->setEventReceiver(&mainGame->dField); cur_replay.Rewind(); const ReplayHeader& rh = cur_replay.pheader; //mainGame->dInfo.isFirst = true; mtrandom rnd; int seed = rh.seed; rnd.reset(seed); if(rh.flag & REPLAY_TAG) { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.hostname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname_tag, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); mainGame->dInfo.isTag = true; mainGame->dInfo.tag_player[0] = false; mainGame->dInfo.tag_player[1] = false; } else { cur_replay.ReadData(mainGame->dInfo.hostname, 40); cur_replay.ReadData(mainGame->dInfo.clientname, 40); } //set_card_reader((card_reader)DataManager::CardReader); //set_message_handler((message_handler)MessageHandler); pduel = create_duel(rnd.rand()); int start_lp = cur_replay.ReadInt32(); int start_hand = cur_replay.ReadInt32(); int draw_count = cur_replay.ReadInt32(); int opt = cur_replay.ReadInt32(); set_player_info(pduel, 0, start_lp, start_hand, draw_count); set_player_info(pduel, 1, start_lp, start_hand, draw_count); mainGame->dInfo.lp[0] = start_lp; mainGame->dInfo.lp[1] = start_lp; myswprintf(mainGame->dInfo.strLP[0], L"%d", mainGame->dInfo.lp[0]); myswprintf(mainGame->dInfo.strLP[1], L"%d", mainGame->dInfo.lp[1]); mainGame->dInfo.turn = 0; if(!(opt & DUEL_TAG_MODE)) { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); } else { int main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); int extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 0, 0, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(0, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 0, LOCATION_EXTRA); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_DECK, 0, POS_FACEDOWN_DEFENSE); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_card(pduel, cur_replay.ReadInt32(), 1, 1, LOCATION_EXTRA, 0, POS_FACEDOWN_DEFENSE); mainGame->dField.Initial(1, main, extra); main = cur_replay.ReadInt32(); for(int i = 0; i < main; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_DECK); extra = cur_replay.ReadInt32(); for(int i = 0; i < extra; ++i) new_tag_card(pduel, cur_replay.ReadInt32(), 1, LOCATION_EXTRA); } start_duel(pduel, opt); if(refresh) { mainGame->dField.RefreshAllCards(); mainGame->dInfo.isStarted = true; //mainGame->dInfo.isReplay = true; } skip_turn = 0; is_restarting = true; }
void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) { if(dp->state != CTOS_TP_RESULT) return; bool swapped = false; mtrandom rnd; pplayer[0] = players[0]; pplayer[1] = players[1]; if((tp && dp->type == 1) || (!tp && dp->type == 0)) { DuelPlayer* p = players[0]; players[0] = players[1]; players[1] = p; players[0]->type = 0; players[1]->type = 1; Deck d = pdeck[0]; pdeck[0] = pdeck[1]; pdeck[1] = d; swapped = true; } dp->state = CTOS_RESPONSE; ReplayHeader rh; rh.id = 0x31707279; rh.version = PRO_VERSION; rh.flag = 0; time_t seed = time(0); rh.seed = seed; last_replay.BeginRecord(); last_replay.WriteHeader(rh); rnd.reset(seed); last_replay.WriteData(players[0]->name, 40, false); last_replay.WriteData(players[1]->name, 40, false); if(!host_info.no_shuffle_deck) { for(size_t i = pdeck[0].main.size() - 1; i > 0; --i) { int swap = rnd.real() * (i + 1); std::swap(pdeck[0].main[i], pdeck[0].main[swap]); } for(size_t i = pdeck[1].main.size() - 1; i > 0; --i) { int swap = rnd.real() * (i + 1); std::swap(pdeck[1].main[i], pdeck[1].main[swap]); } } time_limit[0] = host_info.time_limit; time_limit[1] = host_info.time_limit; set_card_reader((card_reader)DataManager::CardReader); set_message_handler((message_handler)SingleDuel::MessageHandler); rnd.reset(seed); pduel = create_duel(rnd.rand()); set_player_info(pduel, 0, host_info.start_lp, host_info.start_hand, host_info.draw_count); set_player_info(pduel, 1, host_info.start_lp, host_info.start_hand, host_info.draw_count); int opt = 0; if(host_info.enable_priority) opt |= DUEL_OBSOLETE_RULING; if(host_info.no_shuffle_deck) opt |= DUEL_PSEUDO_SHUFFLE; last_replay.WriteInt32(host_info.start_lp, false); last_replay.WriteInt32(host_info.start_hand, false); last_replay.WriteInt32(host_info.draw_count, false); last_replay.WriteInt32(opt, false); last_replay.Flush(); last_replay.WriteInt32(pdeck[0].main.size(), false); for(int32 i = (int32)pdeck[0].main.size() - 1; i >= 0; --i) { new_card(pduel, pdeck[0].main[i]->first, 0, 0, LOCATION_DECK, 0, 0); last_replay.WriteInt32(pdeck[0].main[i]->first, false); } last_replay.WriteInt32(pdeck[0].extra.size(), false); for(int32 i = (int32)pdeck[0].extra.size() - 1; i >= 0; --i) { new_card(pduel, pdeck[0].extra[i]->first, 0, 0, LOCATION_EXTRA, 0, 0); last_replay.WriteInt32(pdeck[0].extra[i]->first, false); } last_replay.WriteInt32(pdeck[1].main.size(), false); for(int32 i = (int32)pdeck[1].main.size() - 1; i >= 0; --i) { new_card(pduel, pdeck[1].main[i]->first, 1, 1, LOCATION_DECK, 0, 0); last_replay.WriteInt32(pdeck[1].main[i]->first, false); } last_replay.WriteInt32(pdeck[1].extra.size(), false); for(int32 i = (int32)pdeck[1].extra.size() - 1; i >= 0; --i) { new_card(pduel, pdeck[1].extra[i]->first, 1, 1, LOCATION_EXTRA, 0, 0); last_replay.WriteInt32(pdeck[1].extra[i]->first, false); } last_replay.Flush(); char startbuf[32], *pbuf = startbuf; BufferIO::WriteInt8(pbuf, MSG_START); BufferIO::WriteInt8(pbuf, 0); BufferIO::WriteInt32(pbuf, host_info.start_lp); BufferIO::WriteInt32(pbuf, host_info.start_lp); BufferIO::WriteInt16(pbuf, query_field_count(pduel, 0, 0x1)); BufferIO::WriteInt16(pbuf, query_field_count(pduel, 0, 0x40)); BufferIO::WriteInt16(pbuf, query_field_count(pduel, 1, 0x1)); BufferIO::WriteInt16(pbuf, query_field_count(pduel, 1, 0x40)); NetServer::SendBufferToPlayer(players[0], STOC_GAME_MSG, startbuf, 18); startbuf[1] = 1; NetServer::SendBufferToPlayer(players[1], STOC_GAME_MSG, startbuf, 18); if(!swapped) startbuf[1] = 0x10; else startbuf[1] = 0x11; for(auto oit = observers.begin(); oit != observers.end(); ++oit) NetServer::SendBufferToPlayer(*oit, STOC_GAME_MSG, startbuf, 18); RefreshExtra(0); RefreshExtra(1); start_duel(pduel, opt); Process(); }