예제 #1
0
int ReplayMode::ReplayThread(void* param) {
	const ReplayHeader& rh = cur_replay.pheader;
	mainGame->dInfo.isFirst = true;
	mainGame->dInfo.isTag = !!(rh.flag & REPLAY_TAG);
	mainGame->dInfo.isSingleMode = !!(rh.flag & REPLAY_SINGLE_MODE);
	mainGame->dInfo.tag_player[0] = false;
	mainGame->dInfo.tag_player[1] = false;
	if(mainGame->dInfo.isSingleMode) {
		set_script_reader((script_reader)SingleMode::ScriptReaderEx);
		set_card_reader((card_reader)DataManager::CardReader);
		set_message_handler((message_handler)MessageHandler);
	} else {
		set_script_reader((script_reader)ScriptReaderEx);
		set_card_reader((card_reader)DataManager::CardReader);
		set_message_handler((message_handler)MessageHandler);
	}
	if(!StartDuel()) {
		EndDuel();
		return 0;
	}
	mainGame->dInfo.isStarted = true;
	mainGame->dInfo.isFinished = false;
	mainGame->dInfo.isReplay = true;
	mainGame->dInfo.isReplaySkiping = (skip_turn > 0);
	char engineBuffer[0x1000];
	is_continuing = true;
	skip_step = 0;
	if(mainGame->dInfo.isSingleMode) {
		int len = get_message(pduel, (byte*)engineBuffer);
		if (len > 0)
			is_continuing = ReplayAnalyze(engineBuffer, len);
	} else {
		ReplayRefreshDeck(0);
		ReplayRefreshDeck(1);
		ReplayRefreshExtra(0);
		ReplayRefreshExtra(1);
	}
	exit_pending = false;
	current_step = 0;
	if(mainGame->dInfo.isReplaySkiping)
		mainGame->gMutex.Lock();
	while (is_continuing && !exit_pending) {
		int result = process(pduel);
		int len = result & 0xffff;
		/*int flag = result >> 16;*/
		if (len > 0) {
			get_message(pduel, (byte*)engineBuffer);
			is_continuing = ReplayAnalyze(engineBuffer, len);
			if(is_restarting) {
				mainGame->gMutex.Lock();
				is_restarting = false;
				int step = current_step - 1;
				if(step < 0)
					step = 0;
				if(mainGame->dInfo.isSingleMode) {
					is_continuing = true;
					skip_step = 0;
					int len = get_message(pduel, (byte*)engineBuffer);
					if (len > 0) {
						mainGame->gMutex.Unlock();
						is_continuing = ReplayAnalyze(engineBuffer, len);
						mainGame->gMutex.Lock();
					}
				}
				if(step == 0) {
					Pause(true, false);
					mainGame->dInfo.isStarted = true;
					mainGame->dInfo.isFinished = false;
					mainGame->dInfo.isReplaySkiping = false;
					mainGame->dField.RefreshAllCards();
					mainGame->gMutex.Unlock();
				}
				skip_step = step;
				current_step = 0;
			}
		}
	}
	if(mainGame->dInfo.isReplaySkiping) {
		mainGame->dInfo.isReplaySkiping = false;
		mainGame->dField.RefreshAllCards();
		mainGame->gMutex.Unlock();
	}
	EndDuel();
	return 0;
}
예제 #2
0
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;
}
예제 #3
0
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;
}