Guest User

Untitled

a guest
Jul 16th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 35.79 KB | None | 0 0
  1. #include "FenPrinc.h"
  2. #include "Code.h"
  3.  
  4. /* Constructeur :   -Inclu les méthodes
  5.                     -Paramètres de la fenêtre
  6. */
  7.  
  8. FenPrinc::FenPrinc()
  9. {
  10.     creaLayout();
  11.     creaMenus();
  12.     initialisations();
  13.     setFixedSize(750, 330);
  14. }
  15.  
  16. /* creaLayout :     -Création des FormLayout
  17.                     -Création des GroupBox
  18. */
  19.  
  20. void FenPrinc::creaLayout()
  21. {
  22.     definitions();
  23.  
  24.     QFormLayout *lCible = new QFormLayout;
  25.     lCible->addRow("Nom du royaume enemi", rCible);
  26.     lCible->addRow("Coordonné X", cX);
  27.     lCible->addRow("Coordonné Y", cY);
  28.     QFormLayout *lRepe = new QFormLayout;
  29.     lRepe->addRow("Nom du royaume repère", rRepere);
  30.     lRepe->addRow("Heure d'attaque", depart);
  31.     lRepe->addRow("Durée de l'attaque", duree);
  32.     lRepe->addRow("Date de l'attaque", date);
  33.     QFormLayout *lMulti = new QFormLayout;
  34.     lMulti->addRow(grPlan);
  35.     lMulti->addRow(plPlan);
  36.     QFormLayout *lSelect = new QFormLayout;
  37.     lSelect->addRow("Alliances disponibles", nSelect);
  38.     lSelect->addRow("Alliances sélectionnées", oSelect);
  39.  
  40.     cible = new QGroupBox("Cible de la planification");
  41.     cible->setLayout(lCible);
  42.     repere = new QGroupBox("Caractéristiques de la planification");
  43.     repere->setLayout(lRepe);
  44.     multi = new QGroupBox("Paramètres multi-alliance");
  45.     multi->setLayout(lMulti);
  46.     selection = new QGroupBox("Alliances");
  47.     selection->setLayout(lSelect);
  48.  
  49.     sub1->addWidget(repere);
  50.     sub1->addWidget(cible);
  51.     sub2->addWidget(selection);
  52.     sub2->addWidget(multi);
  53.     layoutPrincipal->addLayout(sub1);
  54.     layoutPrincipal->addLayout(sub2);
  55.  
  56.     pageRoy->setLayout(layoutPrincipal);
  57.  
  58.     setCentralWidget(onglets);
  59. }
  60.  
  61. // definitions : -Définir les attributs pointeurs
  62.  
  63. void FenPrinc::definitions()
  64. {
  65.     ifis = 1;
  66.     rCible = new QLineEdit;
  67.     rCible->setMaximumWidth(150);
  68.     rCible->setMinimumWidth(150);
  69.     rRepere = new QLineEdit;
  70.     rRepere->setMaximumWidth(150);
  71.     rRepere->setMinimumWidth(150);
  72.     date = new QLineEdit;
  73.     date->setMaximumWidth(150);
  74.     date->setMinimumWidth(150);
  75.     cX = new QSpinBox;
  76.     cX->setMaximumWidth(40);
  77.     cY = new QSpinBox;
  78.     cY->setMaximumWidth(40);
  79.     depart = new QSpinBox;
  80.     depart->setRange(0, 23);
  81.     depart->setMaximumWidth(40);
  82.     duree = new QSpinBox;
  83.     duree->setRange(1, 5);
  84.     duree->setMaximumWidth(40);
  85.     pageRoy = new QWidget(this);
  86.     onglets = new QTabWidget;
  87.     onglets->addTab(pageRoy, "Planification");
  88.     grPlan = new QRadioButton("Générer une grande planification");
  89.     grPlan->setEnabled(false);
  90.     plPlan = new QRadioButton("Générer une planification par alliance");
  91.     plPlan->setEnabled(false);
  92.     layoutPrincipal = new QHBoxLayout;
  93.     sub1 = new QVBoxLayout;
  94.     sub2 = new QVBoxLayout;
  95.     dista = 100;
  96.     nSelect = new QListWidget;
  97.     connect(nSelect, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(changeS(QListWidgetItem *)));
  98.     oSelect = new QListWidget;
  99.     connect(oSelect, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(changeU(QListWidgetItem *)));
  100.     alliance = new QSettings("Alliances", QSettings::IniFormat);
  101.     allSelect = new QSettings("AllSelect", QSettings::IniFormat);
  102.     allSelect->clear();
  103.     generer = new QAction("Générer la planification", this);
  104.     generer->setShortcut(tr("F12"));
  105.     connect(generer, SIGNAL(triggered()), this, SLOT(genererCode()));
  106.     plusAll = new QAction("Ajouter une alliance", this);
  107.     connect(plusAll, SIGNAL(triggered()), this, SLOT(ajouterAll()));
  108.     moinsAll = new QAction("Supprimer une alliance", this);
  109.     connect(moinsAll, SIGNAL(triggered()), this, SLOT(deleteAll()));
  110.     modif = new QAction("Modifier une alliance", this);
  111.     connect(modif, SIGNAL(triggered()), this, SLOT(modifAll()));
  112.     quitt = new QAction("Quitter", this);
  113.     connect(quitt, SIGNAL(triggered()), qApp, SLOT(quit()));
  114.     box = new QComboBox();
  115.     box->setMinimumWidth(200);
  116.     box->addItem("Delos");
  117.     box->addItem("Thessalie");
  118.     box->addItem("Pheres");
  119.     textP = new QLabel("Copyright @ 2011 - xXModz' Universe - gab4powa@hotmail.com");
  120.     statusBar()->addWidget(textP);
  121.     statusBar()->addWidget(box);
  122.  
  123.  
  124. }
  125.  
  126. /*creaMenus :   -Définit les menus
  127.                 -Définit les actions
  128. */
  129.  
  130. void FenPrinc::creaMenus()
  131. {
  132.     QMenu *fichier = menuBar()->addMenu(tr("&Fichier"));
  133.     fichier->addAction(generer);
  134.     fichier->addAction(quitt);
  135.  
  136.     QMenu *para = menuBar()->addMenu("Paramètres alliances");
  137.     para->addAction(plusAll);
  138.     para->addAction(moinsAll);
  139.     para->addAction(modif);
  140. }
  141.  
  142. //genererCode : -Algorythme pour planification
  143.  
  144. void FenPrinc::genererCode()
  145. {
  146.     if(oSelect->count() == 0)
  147.     {
  148.         QMessageBox::critical(this,"Attention!", "Au moins une alliance doit être sélectionnée!");
  149.         return;
  150.     }
  151.  
  152.     int test = trouvDist();
  153.     if(test == 2)
  154.         return;
  155.  
  156.     if(oSelect->count() == 1)
  157.     {
  158.         uneAlliance();
  159.     }
  160.     else if(plPlan->isChecked())
  161.     {
  162.         plAlliance();
  163.     }
  164.     else if(grPlan->isChecked())
  165.     {
  166.         grAlliance();
  167.     }
  168. }
  169.  
  170. //initialisations : -Initialise les préférences
  171.  
  172. void FenPrinc::initialisations()
  173. {
  174.     stringstream nTl;
  175.     int i = 1;
  176.     nTl << i;
  177.     string b = "Alliance" + nTl.str();
  178.     QString end = b.c_str();
  179.     while(alliance->contains(end))
  180.     {
  181.         QListWidgetItem *item  = new QListWidgetItem(alliance->value(end).toString(), nSelect);
  182.         i++;
  183.         stringstream nTl;
  184.         nTl << i;
  185.         b = "Alliance" + nTl.str();
  186.         end = b.c_str();
  187.     }
  188.  
  189. }
  190.  
  191. void FenPrinc::changeU(QListWidgetItem *widget)
  192. {
  193.     nSelect->addItem(widget->text());
  194.  
  195.     stringstream nTl;
  196.     int i = 1;
  197.     nTl << i;
  198.     string b = "Alliance" + nTl.str();
  199.     QString end = b.c_str();
  200.     while(allSelect->value(end) != widget->text())
  201.     {
  202.         i++;
  203.         stringstream nTl;
  204.         nTl << i;
  205.         b = "Alliance" + nTl.str();
  206.         end = b.c_str();
  207.     }
  208.  
  209.     while(true)
  210.     {
  211.         stringstream nTl2;
  212.         int c = i + 1;
  213.         nTl2 << c;
  214.         string a = "Alliance" + nTl2.str();
  215.         QString end2 = a.c_str();
  216.  
  217.         if(allSelect->contains(end2))
  218.         {
  219.             allSelect->setValue(end, allSelect->value(end2));
  220.  
  221.             i++;
  222.  
  223.             stringstream nTl;
  224.             nTl << i;
  225.             string b = "Alliance" + nTl.str();
  226.             QString end = b.c_str();
  227.             allSelect->remove(end);
  228.             break;
  229.         }
  230.         else
  231.         {
  232.             allSelect->remove(end);
  233.             break;
  234.         }
  235.  
  236.     }
  237.     if(!(allSelect->contains("Alliance2")))
  238.         {
  239.             if(grPlan->isEnabled())
  240.             {
  241.                 grPlan->setEnabled(false);
  242.                 plPlan->setEnabled(false);
  243.             }
  244.         }
  245.  
  246.     delete widget;
  247. }
  248.  
  249. int FenPrinc::trouvDist()
  250. {
  251.     if(box->currentText() == "Pheres")
  252.     {
  253.         min = 4;
  254.         max = 23.44;
  255.     }
  256.     else
  257.     {
  258.             min = 3;
  259.     max = 25.44;
  260.     }
  261.  
  262.     int i = 1;
  263.     stringstream ss;
  264.     ss << i;
  265.     string trouver = "Alliance" + ss.str();
  266.  
  267.     while(allSelect->contains(trouver.c_str()))
  268.     {
  269.         int z = 1;
  270.         stringstream aa;
  271.         aa << z;
  272.         string trouv = "Alliance" + aa.str();
  273.  
  274.         while(alliance->value(trouv.c_str()) != allSelect->value(trouver.c_str()))
  275.         {
  276.             z++;
  277.             stringstream aa;
  278.             aa << z;
  279.             trouv = "Alliance" + aa.str();
  280.         }
  281.  
  282.         for(int i = z * 20  - 19 ; i <= z * 20 ; i ++)
  283.         {
  284.             stringstream ss;
  285.             ss << i;
  286.             trouv = "Membre" + ss.str();
  287.  
  288.             if(alliance->value(trouv.c_str()) == rRepere->text())
  289.             {
  290.                 string x = "x" + ss.str();
  291.                 string y = "y" + ss.str();
  292.                 int x1 = alliance->value(x.c_str()).toInt();
  293.                 int y1 = alliance->value(y.c_str()).toInt();
  294.                 int x2 = cX->value();
  295.                 int y2 = cY->value();
  296.                 x1 = fabs(x2 - x1);
  297.                 y1 = fabs(y2 - y1);
  298.                 float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
  299.                 if (ans1 < 9.44)
  300.                 {
  301.                     if(ans1 > 6.41 && ans1 < 7.22)
  302.                         dista = min+2;
  303.                     else if(ans1 >= 7.22)
  304.                         dista = min+3;
  305.  
  306.                     else if(ans1 >= 2.8 && ans1 <= 6.41)
  307.                         dista = min+1;
  308.                     else
  309.                         dista = min;
  310.  
  311.                 }
  312.                 else
  313.                 {
  314.                     float val = 9.44;
  315.                     int heure = min+4;
  316.                     if (ans1 > max)
  317.                      dista = 15;
  318.                     else
  319.                     {
  320.                         while(1)
  321.                         {
  322.                             if(ans1 >= val && ans1 < val+2)
  323.                             {
  324.                                 dista = heure;
  325.                                 break;
  326.                             }
  327.                             val += 2;
  328.                             heure++;
  329.                         }
  330.                     }
  331.                 }
  332.                 return 1;
  333.             }
  334.  
  335.  
  336.         }
  337.  
  338.         i++;
  339.         stringstream ss;
  340.         ss << i;
  341.         trouver = "Alliance" + ss.str();
  342.  
  343.     }
  344.  
  345.     QMessageBox::critical(this,"Attention!", rRepere->text() + " ne fait pas parti des alliances sélectionnées!");
  346.     return 2;
  347.  
  348. }
  349.  
  350. void FenPrinc::changeS(QListWidgetItem *widget)
  351. {
  352.     oSelect->addItem(widget->text());
  353.  
  354.     stringstream nTl;
  355.     int i = 1;
  356.     nTl << i;
  357.     string b = "Alliance" + nTl.str();
  358.     QString end = b.c_str();
  359.     while(allSelect->contains(end))
  360.     {
  361.         i++;
  362.         stringstream nTl;
  363.         nTl << i;
  364.         b = "Alliance" + nTl.str();
  365.         end = b.c_str();
  366.     }
  367.     allSelect->setValue(end, widget->text());
  368.  
  369.     if(allSelect->contains("Alliance2") && !grPlan->isEnabled())
  370.     {
  371.         grPlan->setEnabled(true);
  372.         grPlan->setChecked(true);
  373.         plPlan->setEnabled(true);
  374.     }
  375.  
  376.     delete widget;
  377. }
  378.  
  379. void FenPrinc::uneAlliance()
  380. {
  381.         if(box->currentText() == "Pheres")
  382.     {
  383.         min = 4;
  384.         max = 26;
  385.     }
  386.     else
  387.     {
  388.             min = 3;
  389.     max = 26;
  390.     }
  391.     QString code;
  392.     stringstream out;
  393.     int dure = duree->value();
  394.     out << dure;
  395.     int distance = 0;
  396.  
  397.     int ifno = 0;
  398.     int allSpot = 1;
  399.  
  400.     stringstream aa;
  401.     aa << allSpot;
  402.     string trouv = "Alliance" + aa.str();
  403.  
  404.     while(alliance->value(trouv.c_str()) != allSelect->value("Alliance1"))
  405.     {
  406.         allSpot++;
  407.         stringstream aa;
  408.         aa << allSpot;
  409.         trouv = "Alliance" + aa.str();
  410.     }
  411.  
  412.     code += allSelect->value("Alliance1").toString() + "\n\n";
  413.     code += "Planification contre " + rCible->text() + "\nDuree de l'attaque : " + out.str().c_str() + " Heures \nDate : " + date->text()+ "\n\n\n";
  414.  
  415.         for(int b = 15 ; b > 2 ; b--)
  416.         {
  417.             for(int i = allSpot * 20  - 19 ; i <= allSpot * 20 ; i ++)
  418.             {
  419.                 stringstream out;
  420.                 out << i;
  421.                 string x = "x" + out.str();
  422.                 string y = "y" + out.str();
  423.                 int x1 = alliance->value(x.c_str()).toInt();
  424.                 int y1 = alliance->value(y.c_str()).toInt();
  425.                 if(x1 != 0)
  426.                 {
  427.                     int x2 = cX->value();
  428.                     int y2 = cY->value();
  429.                     x1 = fabs(x2 - x1);
  430.                     y1 = fabs(y2 - y1);
  431.                     float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
  432.  
  433.                 if (ans1 < 9.44)
  434.                 {
  435.                     if(ans1 > 6.41 && ans1 < 7.22)
  436.                         distance = min+2;
  437.                     else if(ans1 >= 7.22)
  438.                         distance = min+3;
  439.  
  440.                     else if(ans1 >= 2.8 && ans1 <= 6.41)
  441.                         distance = min+1;
  442.                     else
  443.                         distance = min;
  444.  
  445.                 }
  446.                 else
  447.                 {
  448.                     float val = 9.44;
  449.                     int heure = min+4;
  450.                     if (ans1 > max)
  451.                      distance = 15;
  452.                         else
  453.                         {
  454.                             while(1)
  455.                             {
  456.                                 if(ans1 >= val && ans1 < val+2)
  457.                                 {
  458.                                     distance = heure;
  459.                                     break;
  460.                                 }
  461.                                 val += 2;
  462.                                 heure++;
  463.                             }
  464.                         }
  465.                     }
  466.  
  467.                 }
  468.                 else
  469.                     distance = -1;
  470.  
  471.                 if(distance == b)
  472.                 {
  473.                     int moyen = dista - b;
  474.                     int timee = depart->value() + moyen;
  475.                     if(timee < 0)
  476.                     {
  477.                         timee = 24 + timee;
  478.                     }
  479.                     else if(timee > 23)
  480.                     {
  481.                         timee = -24 + timee;
  482.                     }
  483.                     stringstream d1, d2;
  484.                     d1 << timee;
  485.                     d2 << timee + 1;
  486.                     stringstream bo;
  487.                     bo << b;
  488.                     if(ifno == 0)
  489.                     {
  490.                         code +="\n";
  491.                         code += "Ceux qui doivent partir entre ";
  492.                         code += d1.str().c_str();
  493.                         code += "h30  et " ;
  494.                         code += d2.str().c_str();
  495.                         code += "h30 (";
  496.                         code += bo.str().c_str();
  497.                         code += " Heures de distance) : ";
  498.                         code += "\n\n";
  499.                         ifno = 1;
  500.                     }
  501.                     stringstream bob;
  502.                     bob << i;
  503.                     string go = "Membre" + bob.str();
  504.                     QString boo = go.c_str();
  505.                     QString duuude = alliance->value(boo).toString();
  506.                     code += duuude;
  507.                     code += "\n";
  508.  
  509.                 }
  510.  
  511.                 }
  512.             ifno = 0;
  513.             }
  514.  
  515.     Planif *planif = new Planif(code, this);
  516.     planif->show();
  517. }
  518. void FenPrinc::grAlliance()
  519. {
  520.         if(box->currentText() == "Pheres")
  521.     {
  522.         min = 4;
  523.         max = 26;
  524.     }
  525.     else
  526.     {
  527.             min = 3;
  528.     max = 26;
  529.     }
  530.     QString code;
  531.     stringstream out;
  532.     int dure = duree->value();
  533.     out << dure;
  534.     int distance = 0;
  535.     int ifno = 0;
  536.     augAll = 0;
  537.  
  538.     stringstream nomAll;
  539.     int nomAl = 1;
  540.     nomAll << nomAl;
  541.     string nomA = "Alliance" + nomAll.str();
  542.  
  543.     while(allSelect->contains(nomA.c_str()))
  544.     {
  545.         code += allSelect->value(nomA.c_str()).toString() + "\n";
  546.         stringstream nomAll;
  547.         nomAl++;
  548.         nomAll << nomAl;
  549.         nomA = "Alliance" + nomAll.str();
  550.     }
  551.  
  552.  
  553.     code += "\n\n";
  554.     code += "Planification contre " + rCible->text() + "\nDuree de l'attaque : " + out.str().c_str() + " Heures \nDate : " + date->text()+ "\n\n\n";
  555.         for(int b = 15 ; b > 2 ; b--)
  556.         {
  557.             augAll = 0;
  558.             stringstream plusAll;
  559.             plusAll << 1;
  560.             string kelAll = "Alliance" + plusAll.str();
  561.             int allSpot = 1;
  562.             stringstream aa;
  563.             aa << allSpot;
  564.             string trouv = "Alliance" + aa.str();
  565.             int bob = 5;
  566.  
  567.             while(alliance->value(trouv.c_str()) != allSelect->value(kelAll.c_str()))
  568.             {
  569.                 allSpot++;
  570.                 stringstream aa;
  571.                 aa << allSpot;
  572.                 trouv = "Alliance" + aa.str();
  573.             }
  574.  
  575.  
  576.             while(true)
  577.             {
  578.                     augAll++;
  579.  
  580.                 stringstream next;
  581.                     next << augAll;
  582.                     string nextAll = "Alliance" + next.str();
  583.                     if(allSelect->contains(nextAll.c_str()))
  584.                     {
  585.                             stringstream plusAll;
  586.                             plusAll << augAll;
  587.                             string kelAll = "Alliance" + plusAll.str();
  588.                             allSpot = 1;
  589.                             stringstream aa;
  590.                             aa << allSpot;
  591.                             string trouv = "Alliance" + aa.str();
  592.  
  593.                             while(alliance->value(trouv.c_str()) != allSelect->value(kelAll.c_str()))
  594.                             {
  595.                                 allSpot++;
  596.                                 stringstream aa;
  597.                                 aa << allSpot;
  598.                                 trouv = "Alliance" + aa.str();
  599.                             }
  600.                     }
  601.                     else
  602.                     break;
  603.  
  604.             for(int i = allSpot * 20  - 19 ; i <= allSpot * 20 ; i ++)
  605.             {
  606.                 stringstream out;
  607.                 out << i;
  608.                 string x = "x" + out.str();
  609.                 string y = "y" + out.str();
  610.                 int x1 = alliance->value(x.c_str()).toInt();
  611.                 int y1 = alliance->value(y.c_str()).toInt();
  612.                 if(x1 != 0)
  613.                 {
  614.                     int x2 = cX->value();
  615.                     int y2 = cY->value();
  616.                     x1 = fabs(x2 - x1);
  617.                     y1 = fabs(y2 - y1);
  618.                     float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
  619.  
  620.                 if (ans1 < 9.44)
  621.                 {
  622.                     if(ans1 > 6.41 && ans1 < 7.22)
  623.                         distance = min+2;
  624.                     else if(ans1 >= 7.22)
  625.                         distance = min+3;
  626.  
  627.                     else if(ans1 >= 2.8 && ans1 <= 6.41)
  628.                         distance = min+1;
  629.                     else
  630.                         distance = min;
  631.  
  632.                 }
  633.                 else
  634.                 {
  635.                     float val = 9.44;
  636.                     int heure = min+4;
  637.                     if (ans1 > max)
  638.                          distance = 15;
  639.                         else
  640.                         {
  641.                             while(1)
  642.                             {
  643.                                 if(ans1 >= val && ans1 < val+2)
  644.                                 {
  645.                                     distance = heure;
  646.                                     break;
  647.                                 }
  648.                                 val += 2;
  649.                                 heure++;
  650.                             }
  651.                         }
  652.                     }
  653.  
  654.                 }
  655.                 else
  656.                     distance = -1;
  657.  
  658.                 if(distance == b)
  659.                 {
  660.                     int moyen = dista - b;
  661.                     int timee = depart->value() + moyen;
  662.                     if(timee < 0)
  663.                     {
  664.                         timee = 24 + timee;
  665.                     }
  666.                     else if(timee > 23)
  667.                     {
  668.                         timee = -24 + timee;
  669.                     }
  670.                     stringstream d1, d2;
  671.                     d1 << timee - 1;
  672.                     d2 << timee;
  673.                     stringstream bo;
  674.                     bo << b;
  675.                     if(ifno == 0)
  676.                     {
  677.                         code +="\n";
  678.                         code += "Ceux qui doivent partir entre ";
  679.                         code += d1.str().c_str();
  680.                         code += "h30  et " ;
  681.                         code += d2.str().c_str();
  682.                         code += "h30 (";
  683.                         code += bo.str().c_str();
  684.                         code += " Heures de distance) : ";
  685.                         code += "\n\n";
  686.                         ifno = 1;
  687.                     }
  688.                     stringstream bob;
  689.                     bob << i;
  690.                     string go = "Membre" + bob.str();
  691.                     QString boo = go.c_str();
  692.                     QString duuude = alliance->value(boo).toString();
  693.                     code += duuude;
  694.                     code += "\n";
  695.  
  696.                 }
  697.                 }
  698.  
  699.                 }
  700.             ifno = 0;
  701.             }
  702.  
  703.     Planif *planif = new Planif(code, this);
  704.     planif->show();
  705.  
  706. }
  707. void FenPrinc::plAlliance()
  708. {
  709.         if(box->currentText() == "Pheres")
  710.     {
  711.         min = 4;
  712.         max = 26;
  713.     }
  714.     else
  715.     {
  716.             min = 3;
  717.     max = 26;
  718.     }
  719.     int y = 1;
  720.     stringstream allChange;
  721.     allChange << y;
  722.     string boby = "Alliance" + allChange.str();
  723.     while(allSelect->contains(boby.c_str()))
  724.     {
  725.  
  726.     QString code;
  727.     stringstream out;
  728.     int dure = duree->value();
  729.     out << dure;
  730.     int distance = 0;
  731.  
  732.     int ifno = 0;
  733.     int allSpot = 1;
  734.  
  735.     stringstream aa;
  736.     aa << allSpot;
  737.     string trouv = "Alliance" + aa.str();
  738.  
  739.     while(alliance->value(trouv.c_str()) != allSelect->value(boby.c_str()))
  740.     {
  741.         allSpot++;
  742.         stringstream aa;
  743.         aa << allSpot;
  744.         trouv = "Alliance" + aa.str();
  745.     }
  746.  
  747.     code += allSelect->value(boby.c_str()).toString() + "\n\n";
  748.     code += "Planification contre " + rCible->text() + "\nDuree de l'attaque : " + out.str().c_str() + " Heures \nDate : " + date->text()+ "\n\n\n";
  749.  
  750.         for(int b = 15 ; b > 2 ; b--)
  751.         {
  752.             for(int i = allSpot * 20  - 19 ; i <= allSpot * 20 ; i ++)
  753.             {
  754.                 stringstream out;
  755.                 out << i;
  756.                 string x = "x" + out.str();
  757.                 string y = "y" + out.str();
  758.                 int x1 = alliance->value(x.c_str()).toInt();
  759.                 int y1 = alliance->value(y.c_str()).toInt();
  760.                 if(x1 != 0)
  761.                 {
  762.                     int x2 = cX->value();
  763.                     int y2 = cY->value();
  764.                     x1 = fabs(x2 - x1);
  765.                     y1 = fabs(y2 - y1);
  766.                     float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
  767.  
  768.                     if (ans1 < 9.44)
  769.                 {
  770.                     if(ans1 > 6.41 && ans1 < 7.22)
  771.                         distance = min+2;
  772.                     else if(ans1 >= 7.22)
  773.                         distance = min+3;
  774.  
  775.                     else if(ans1 >= 2.8 && ans1 <= 6.41)
  776.                         distance = min+1;
  777.                     else
  778.                         distance = min;
  779.  
  780.                 }
  781.                 else
  782.                 {
  783.                     float val = 9.44;
  784.                     int heure = min+4;
  785.                     if (ans1 > max)
  786.                          distance = 15;
  787.                         else
  788.                         {
  789.                             while(1)
  790.                             {
  791.                                 if(ans1 >= val && ans1 < val+2)
  792.                                 {
  793.                                     distance = heure;
  794.                                     break;
  795.                                 }
  796.                                 val += 2;
  797.                                 heure++;
  798.                             }
  799.                         }
  800.                     }
  801.  
  802.                 }
  803.                 else
  804.                     distance = -1;
  805.  
  806.                 if(distance == b)
  807.                 {
  808.                     int moyen = dista - b;
  809.                     int timee = depart->value() + moyen;
  810.                     if(timee < 0)
  811.                     {
  812.                         timee = 24 + timee;
  813.                     }
  814.                     else if(timee > 23)
  815.                     {
  816.                         timee = -24 + timee;
  817.                     }
  818.                     stringstream d1, d2;
  819.                     d1 << timee;
  820.                     d2 << timee + 1;
  821.                     stringstream bo;
  822.                     bo << b;
  823.                     if(ifno == 0)
  824.                     {
  825.                         code +="\n";
  826.                         code += "Ceux qui doivent partir entre ";
  827.                         code += d1.str().c_str();
  828.                         code += "h30  et " ;
  829.                         code += d2.str().c_str();
  830.                         code += "h30 (";
  831.                         code += bo.str().c_str();
  832.                         code += " Heures de distance) : ";
  833.                         code += "\n\n";
  834.                         ifno = 1;
  835.                     }
  836.                     stringstream bob;
  837.                     bob << i;
  838.                     string go = "Membre" + bob.str();
  839.                     QString boo = go.c_str();
  840.                     QString duuude = alliance->value(boo).toString();
  841.                     code += duuude;
  842.                     code += "\n";
  843.  
  844.                 }
  845.  
  846.                 }
  847.             ifno = 0;
  848.             }
  849.  
  850.     Planif *planif = new Planif(code, this);
  851.     planif->show();
  852.     y++;
  853.     stringstream allChange;
  854.     allChange << y;
  855.     boby = "Alliance" + allChange.str();
  856.  
  857.     }
  858. }
  859.  
  860. void FenPrinc::ajouterAll()
  861. {
  862.     fenetr = new QWidget;
  863.     bUser = new QLineEdit;
  864.     QPushButton *boutonC = new QPushButton;
  865.     boutonC->setText(tr("Ajouter"));
  866.     connect(boutonC, SIGNAL(clicked()), this, SLOT(addAll()));
  867.     connect(boutonC, SIGNAL(clicked()), fenetr, SLOT(close()));
  868.     QFormLayout *definitionLayout = new QFormLayout;
  869.     definitionLayout->addRow(tr("Nom"), bUser);
  870.     QGroupBox *rec = new QGroupBox(tr("Ajouter une alliance"));
  871.     rec->setLayout(definitionLayout);
  872.     rec->setFixedSize(300, 70);
  873.     QVBoxLayout bigL;
  874.     bigL.addWidget(rec);
  875.     bigL.addWidget(boutonC);
  876.     fenetr->setLayout(&bigL);
  877.     fenetr->setFixedSize(320, 120);
  878.     fenetr->show();
  879.  
  880. }
  881.  
  882. void FenPrinc::addAll()
  883. {
  884.     int i = 1;
  885.     stringstream chiffre;
  886.     chiffre << i;
  887.     string quelAll = "Alliance" + chiffre.str();
  888.     while(alliance->contains(quelAll.c_str()))
  889.     {
  890.         if(alliance->value(quelAll.c_str()) == bUser->text())
  891.         {
  892.             QMessageBox::critical(this,"Erreur", "Une alliance porte déjà ce nom!");
  893.             return;
  894.         }
  895.  
  896.         i++;
  897.         stringstream chiffre;
  898.         chiffre << i;
  899.         quelAll = "Alliance" + chiffre.str();
  900.     }
  901.     alliance->setValue(quelAll.c_str(), bUser->text());
  902.     for(int l = i * 20 - 19 ; l <= i * 20 ; l++)
  903.     {
  904.         stringstream chiffre;
  905.         chiffre << l;
  906.         string memb = "Membre" + chiffre.str();
  907.         string x1 = "x" + chiffre.str();
  908.         string y1 = "y" + chiffre.str();
  909.         alliance->setValue(memb.c_str(), "Emplacement vide");
  910.         alliance->setValue(x1.c_str(), 0);
  911.         alliance->setValue(y1.c_str(), 0);
  912.     }
  913.  
  914.     chgAll();
  915. }
  916.  
  917. void FenPrinc::chgAll()
  918. {
  919.     nSelect->clear();
  920.     oSelect->clear();
  921.     allSelect->clear();
  922.     initialisations();
  923. }
  924.  
  925. void FenPrinc::deleteAll()
  926. {
  927.     fenetre = new QWidget;
  928.     aUser = new QLineEdit;
  929.     QPushButton *boutonC = new QPushButton;
  930.     boutonC->setText(tr("Supprimer"));
  931.     connect(boutonC, SIGNAL(clicked()), this, SLOT(delAll()));
  932.     connect(boutonC, SIGNAL(clicked()), fenetre, SLOT(close()));
  933.     QFormLayout *definitionLayout = new QFormLayout;
  934.     definitionLayout->addRow(tr("Nom"), aUser);
  935.     QGroupBox *rec = new QGroupBox(tr("Supprimer une alliance"));
  936.     rec->setLayout(definitionLayout);
  937.     rec->setFixedSize(300, 70);
  938.     QVBoxLayout bigL;
  939.     bigL.addWidget(rec);
  940.     bigL.addWidget(boutonC);
  941.     fenetre->setLayout(&bigL);
  942.     fenetre->setFixedSize(320, 120);
  943.     fenetre->show();
  944. }
  945.  
  946. void FenPrinc::delAll()
  947. {
  948.     int reponse = QMessageBox::critical(this, "Supprimer une alliance", "Êtes-vous sur de vouloir supprimer l'alliance suivant : " + aUser->text() + " ?", QMessageBox::Yes | QMessageBox::No);
  949.     if (reponse == QMessageBox::Yes)
  950.     {
  951.         int i = 1;
  952.         stringstream chiffre;
  953.         chiffre << i;
  954.         string quelAll = "Alliance" + chiffre.str();
  955.         while(alliance->value(quelAll.c_str()) != aUser->text())
  956.         {
  957.             i++;
  958.             stringstream chiffre;
  959.             chiffre << i;
  960.             quelAll = "Alliance" + chiffre.str();
  961.             if(!alliance->contains(quelAll.c_str()))
  962.             {
  963.                 QMessageBox::critical(this,"Attention!", aUser->text() + " ne fait pas partit des alliances en librairie.");
  964.                 return;
  965.             }
  966.         }
  967.         alliance->remove(quelAll.c_str());
  968.         for(int l = i * 20 - 19 ; l <= i * 20 ; l++)
  969.         {
  970.             stringstream chiffre;
  971.             chiffre << l;
  972.             string memb = "Membre" + chiffre.str();
  973.             string x1 = "x" + chiffre.str();
  974.             string y1 = "y" + chiffre.str();
  975.             alliance->remove(memb.c_str());
  976.             alliance->remove(x1.c_str());
  977.             alliance->remove(y1.c_str());
  978.         }
  979.             while(true)
  980.             {
  981.                 stringstream nTl;
  982.                 nTl << i;
  983.                 string b = "Alliance" + nTl.str();
  984.                 QString end = b.c_str();
  985.                 stringstream nTl2;
  986.                 int c = i + 1;
  987.                 nTl2 << c;
  988.                 string a = "Alliance" + nTl2.str();
  989.                 QString end2 = a.c_str();
  990.  
  991.                 if(alliance->contains(end2))
  992.                 {
  993.                     alliance->setValue(end, alliance->value(end2));
  994.                     for(int k = i * 20 - 19 ; k <= i * 20 ; k++)
  995.                     {
  996.                         stringstream nTl;
  997.                         nTl << k;
  998.                         string b = "x" + nTl.str();
  999.                         QString end = b.c_str();
  1000.                         string a = "y" + nTl.str();
  1001.                         QString end2 = a.c_str();
  1002.                         string v = "Membre" + nTl.str();
  1003.                         QString end3 = v.c_str();
  1004.                         stringstream nTl2;
  1005.                         int y = k + 20;
  1006.                         nTl2 << y;
  1007.                         string o = "x" + nTl2.str();
  1008.                         QString boby = o.c_str();
  1009.                         string p = "y" + nTl2.str();
  1010.                         QString bobyy = p.c_str();
  1011.                         string f = "Membre" + nTl2.str();
  1012.                         QString bobyyy = f.c_str();
  1013.                         alliance->setValue(end, alliance->value(boby));
  1014.                         alliance->setValue(end2,alliance->value(bobyy));
  1015.                         alliance->setValue(end3,alliance->value(bobyyy));
  1016.                     }
  1017.  
  1018.  
  1019.                     i++;
  1020.  
  1021.                     stringstream nTl;
  1022.                     nTl << i;
  1023.                     string b = "Alliance" + nTl.str();
  1024.                     QString end = b.c_str();
  1025.                 }
  1026.                 else
  1027.                 {
  1028.                     alliance->remove(end);
  1029.                     for(int k = i * 20 - 19 ; k <= i * 20 ; k++)
  1030.                     {
  1031.                         stringstream nTl;
  1032.                         nTl << k;
  1033.                         string b = "x" + nTl.str();
  1034.                         QString end = b.c_str();
  1035.                         string a = "y" + nTl.str();
  1036.                         QString end2 = a.c_str();
  1037.                         string v = "Membre" + nTl.str();
  1038.                         QString end3 = v.c_str();
  1039.                         stringstream nTl2;
  1040.                         alliance->remove(end);
  1041.                         alliance->remove(end2);
  1042.                         alliance->remove(end3);
  1043.  
  1044.                     }
  1045.                     break;
  1046.                 }
  1047.  
  1048.             }
  1049.  
  1050.         chgAll();
  1051.     }
  1052.  
  1053. }
  1054.  
  1055. void FenPrinc::modifAll()
  1056. {
  1057.     QWidget *fenetre = new QWidget;
  1058.     cUser = new QLineEdit;
  1059.     QPushButton *boutonC = new QPushButton;
  1060.     boutonC->setText(tr("Modifier"));
  1061.     connect(boutonC, SIGNAL(clicked()), this, SLOT(modAll()));
  1062.     connect(boutonC, SIGNAL(clicked()), fenetre, SLOT(close()));
  1063.     QFormLayout *definitionLayout = new QFormLayout;
  1064.     definitionLayout->addRow(tr("Nom"), cUser);
  1065.     QGroupBox *rec = new QGroupBox(tr("Choisir une alliance"));
  1066.     rec->setLayout(definitionLayout);
  1067.     rec->setFixedSize(300, 70);
  1068.     QVBoxLayout bigL;
  1069.     bigL.addWidget(rec);
  1070.     bigL.addWidget(boutonC);
  1071.     fenetre->setLayout(&bigL);
  1072.     fenetre->setFixedSize(320, 120);
  1073.     fenetre->show();
  1074. }
  1075.  
  1076. void FenPrinc::modAll()
  1077. {
  1078.     rNo = new QLineEdit;
  1079.     rNo->setMaximumWidth(150);
  1080.     rNo->setMinimumWidth(150);
  1081.     rX = new QSpinBox;
  1082.     rX->setMaximumWidth(40);
  1083.     rY = new QSpinBox;
  1084.     rY->setMaximumWidth(40);
  1085.     modifi = new QPushButton("Modifier");
  1086.     modifi->setMaximumWidth(150);
  1087.     connect(modifi, SIGNAL(clicked()), this, SLOT(modCli()));
  1088.     int c = 1;
  1089.     int e = 0;
  1090.     stringstream val;
  1091.     val << c;
  1092.     string all = "Alliance" + val.str();
  1093.     while(alliance->contains(all.c_str()))
  1094.     {
  1095.         e++;
  1096.         c++;
  1097.         stringstream val;
  1098.         val << c;
  1099.         all = "Alliance" + val.str();
  1100.     }
  1101.     c = 1;
  1102.  
  1103.     for(int i = 1 ; i <= e; i++)
  1104.     {
  1105.  
  1106.         stringstream val;
  1107.         val << i;
  1108.         all = "Alliance" + val.str();
  1109.         if(alliance->value(all.c_str()) == cUser->text())
  1110.          break;
  1111.         if(i == e)
  1112.         {
  1113.             QMessageBox::critical(this,"Attention!", cUser->text() + " ne fait pas partit des alliances en librairie.");
  1114.             return;
  1115.         }
  1116.         c++;
  1117.     }
  1118.  
  1119.     QHBoxLayout *base1 = new QHBoxLayout;
  1120.  
  1121.     QWidget *fenetre = new QWidget;
  1122.     fenetre->setFixedSize(550, 186);
  1123.     lWidget = new QListWidget;
  1124.     connect(lWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(choixNom(QListWidgetItem *)));
  1125.     QFormLayout *lNoms = new QFormLayout;
  1126.     lNoms->addRow("Nom des royaumes", lWidget);
  1127.     QGroupBox *groupo = new QGroupBox("Royaumes");
  1128.     groupo->setLayout(lNoms);
  1129.     QFormLayout *lModif = new QFormLayout;
  1130.     lModif->addRow("Nom du royaume", rNo);
  1131.     lModif->addRow("Coordonné X", rX);
  1132.     lModif->addRow("Coordonné Y", rY);
  1133.     lModif->addWidget(modifi);
  1134.     QGroupBox *reper = new QGroupBox("Caractéristiques du royaume");
  1135.     reper->setLayout(lModif);
  1136.  
  1137.     base1->addWidget(groupo);
  1138.     base1->addWidget(reper);
  1139.  
  1140.     for(int i = c * 20 - 19 ; i <= c * 20 ; i++)
  1141.     {
  1142.         stringstream val;
  1143.         val << i;
  1144.         all = "Membre" + val.str();
  1145.         QListWidgetItem *item  = new QListWidgetItem(alliance->value(all.c_str()).toString(), lWidget);
  1146.     }
  1147.  
  1148.     fenetre->setLayout(base1);
  1149.     fenetre->show();
  1150.  
  1151. }
  1152.  
  1153. void FenPrinc::choixNom(QListWidgetItem *item)
  1154. {
  1155.     rowName = lWidget->row(item);
  1156.     int l = 1;
  1157.     stringstream check;
  1158.     check << l;
  1159.     string alli = "Alliance" + check.str();
  1160.     while(alliance->value(alli.c_str()) != cUser->text())
  1161.     {
  1162.         l++;
  1163.         stringstream check;
  1164.         check << l;
  1165.         alli = "Alliance" + check.str();
  1166.     }
  1167.     w = l * 20 - 19 + rowName;
  1168.         stringstream chec;
  1169.         chec << w;
  1170.         string mem = "Membre" + chec.str();
  1171.             string rx = "x" + chec.str();
  1172.             string ry = "y" + chec.str();
  1173.             rNo->setText(alliance->value(mem.c_str()).toString());
  1174.             rX->setValue(alliance->value(rx.c_str()).toInt());
  1175.             rY->setValue(alliance->value(ry.c_str()).toInt());
  1176.     pOint = new QListWidgetItem;
  1177.     pOint = item;
  1178. }
  1179.  
  1180. void FenPrinc::modCli()
  1181. {
  1182.     stringstream check;
  1183.     check << w;
  1184.     string mem = "Membre" + check.str();
  1185.     string rx = "x" + check.str();
  1186.     string ry = "y" + check.str();
  1187.     if(rNo->text() == "")
  1188.     {
  1189.         alliance->setValue(mem.c_str(), "Emplacement vide");
  1190.         alliance->setValue(rx.c_str(), 0);
  1191.         alliance->setValue(ry.c_str(), 0);
  1192.         pOint->setText("Emplacement vide");
  1193.         return;
  1194.     }
  1195.     alliance->setValue(mem.c_str(), rNo->text());
  1196.     alliance->setValue(rx.c_str(), rX->value());
  1197.     alliance->setValue(ry.c_str(), rY->value());
  1198.     pOint->setText(rNo->text());
  1199. }
Add Comment
Please, Sign In to add comment