From b4b533b72492da38381ad2fbb6c5aad99e30f110 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Thu, 26 Jan 2017 00:23:53 +0100 Subject: [PATCH] finished legacy loading process --- aoapplication.cpp | 3 -- courtroom.cpp | 16 +++++++ courtroom.h | 1 + datatypes.h | 2 + packet_distribution.cpp | 98 +++++++++++++++++++++++++++++++++++++---- 5 files changed, 109 insertions(+), 11 deletions(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index bf73434..5388fc0 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -54,9 +54,6 @@ void AOApplication::construct_courtroom() w_courtroom = new Courtroom(this); courtroom_constructed = true; - - //D3BUG - w_courtroom->show(); } void AOApplication::destruct_courtroom() diff --git a/courtroom.cpp b/courtroom.cpp index 231d6e9..282c70c 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -296,6 +296,22 @@ void Courtroom::set_size_and_pos(QWidget *p_widget, QString p_identifier) p_widget->resize(design_ini_result.width, design_ini_result.height); } +void Courtroom::set_taken(int n_char, bool p_taken) +{ + if (n_char >= char_list.size()) + { + qDebug() << "W: set_taken attempted to set an index bigger than char_list size"; + return; + } + + char_type f_char; + f_char.name = char_list.at(0).name; + f_char.description = char_list.at(1).description; + f_char.taken = p_taken; + + char_list.replace(n_char, f_char); +} + void Courtroom::on_change_character_clicked() { ui_char_select_background->show(); diff --git a/courtroom.h b/courtroom.h index 1278c83..ec31961 100644 --- a/courtroom.h +++ b/courtroom.h @@ -31,6 +31,7 @@ public: void set_widgets(); void set_size_and_pos(QWidget *p_widget, QString p_identifier); + void set_taken(int n_char, bool p_taken); ~Courtroom(); diff --git a/datatypes.h b/datatypes.h index 0d396bf..9fe5016 100644 --- a/datatypes.h +++ b/datatypes.h @@ -26,12 +26,14 @@ struct char_type { QString name; QString description; + bool taken; }; struct evi_type { QString name; QString description; + QString image; }; struct chatmessage_type diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 84ace31..a20429e 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -157,6 +157,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (f_contents.at(n_element).toInt() != loaded_chars) break; + //this means we are on the last element and checking n + 1 element will be game over so if (n_element == f_contents.size() - 1) break; @@ -167,6 +168,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) char_type f_char; f_char.name = sub_elements.at(0); f_char.description = sub_elements.at(1); + //temporary. the CharsCheck packet sets this properly + f_char.taken = false; ++loaded_chars; @@ -177,28 +180,107 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (loaded_chars < char_list_size) { - qDebug() << "loaded_chars" << loaded_chars; QString next_packet_number = QString::number(((loaded_chars - 1) / 10) + 1); - AOPacket *f_packet = new AOPacket("AN#" + next_packet_number + "#%"); - send_server_packet(f_packet); + send_server_packet(new AOPacket("AN#" + next_packet_number + "#%")); } - else if (loaded_chars >= char_list_size) + else { if (evidence_list_size == 0) send_server_packet(new AOPacket("AM#0#%")); else send_server_packet(new AOPacket("AE#0#%")); } - - - } else if (header == "EI"){ + if (!courtroom_constructed) + return; + + // +1 because evidence starts at 1 rather than 0 for whatever reason + //enjoy fanta + if (f_contents.at(0).toInt() != loaded_evidence + 1) + return; + + if (f_contents.size() < 2) + return; + + QStringList sub_elements = f_contents.at(1).split("&"); + if (sub_elements.size() < 4) + return; + + evi_type f_evi; + f_evi.name = sub_elements.at(0); + f_evi.description = sub_elements.at(1); + //no idea what the number at position 2 is. probably an identifier? + f_evi.image = sub_elements.at(3); + + ++loaded_evidence; + + w_lobby->set_loading_text("Loading evidence:\n" + QString::number(loaded_evidence) + "/" + QString::number(evidence_list_size)); + + w_courtroom->append_evidence(f_evi); + + if (loaded_evidence < evidence_list_size) + { + qDebug() << "loaded evidence: " << loaded_evidence; + QString next_packet_number = QString::number(loaded_evidence); + send_server_packet(new AOPacket("AE#" + next_packet_number + "#%")); + } + else + { + send_server_packet(new AOPacket("AM#0#%")); + } } - else if (header == "EM"){ + else if (header == "EM") + { + if (!courtroom_constructed) + return; + for (int n_element = 0 ; n_element < f_contents.size() ; n_element += 2) + { + if (f_contents.at(n_element).toInt() != loaded_music) + break; + + if (n_element == f_contents.size() - 1) + break; + + QString f_music = f_contents.at(n_element + 1); + + ++loaded_music; + + w_lobby->set_loading_text("Loading music:\n" + QString::number(loaded_music) + "/" + QString::number(music_list_size)); + + w_courtroom->append_music(f_music); + } + + //apparently we need to intentionally send another AM packet to get onwards in the loading process + //in spite of the fact that we actually received all the music + //enjoy fanta + //if (loaded_music < music_list_size) + //{ + QString next_packet_number = QString::number(((loaded_music - 1) / 10) + 1); + send_server_packet(new AOPacket("AM#" + next_packet_number + "#%")); + //} + } + if (header == "CharsCheck") + { + for (int n_char = 0 ; n_char < f_contents.size() ; ++n_char) + { + if (f_contents.at(n_char) == "-1") + w_courtroom->set_taken(n_char, true); + else + w_courtroom->set_taken(n_char, false); + } + } + if (header == "DONE") + { + if (!courtroom_constructed) + return; + + w_courtroom->show(); + + destruct_lobby(); } }