Warning, file /games/ksirk/ksirk/gestionSprites.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of KsirK.
0002    Copyright (C) 2001-2007 Gael de Chalendar <kleag@free.fr>
0003 
0004    KsirK is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, either version 2
0007    of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program; if not, write to the Free Software
0016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017    02110-1301, USA
0018 */
0019 
0020 /*  begin                : Sat Sep 1 2001  */
0021 
0022 /**
0023  * KGameWindow methods for sprites handling function of the state
0024  */
0025 
0026 // application specific includes
0027 #include "kgamewin.h"
0028 #include "Sprites/backgnd.h"
0029 #include "ksirksettings.h"
0030 #include "Sprites/animspritesgroup.h"
0031 #include "Sprites/cannonsprite.h"
0032 #include "Sprites/cavalrysprite.h"
0033 #include "Sprites/infantrysprite.h"
0034 #include "Sprites/arrowsprite.h"
0035 #include "Sprites/skinSpritesData.h"
0036 #include "GameLogic/KMessageParts.h"
0037 #include "GameLogic/onu.h"
0038 #include "fightArena.h"
0039 
0040 // include files for QT
0041 #include <QMetaObject>
0042 #include <QDir>
0043 #include <QPainter>
0044 #include <QInputDialog>
0045 
0046 // include files for KDE
0047 #include <KMessageBox>
0048 #include <KLocalizedString>
0049 #include <KConfig>
0050 #include <KStandardAction>
0051 #include <phonon/mediaobject.h>
0052 #include "ksirk_debug.h"
0053 #include <KToolBar>
0054 
0055 #include <assert.h>
0056 
0057 namespace Ksirk
0058 {
0059 using namespace GameLogic;
0060 
0061 /**
0062  * Prepares the sprites to be moved : removes the nb necessary sprites from
0063  * source, creates the moving sprites and gives them their destination, etc
0064  */
0065 bool KGameWindow::initArmiesMovement(unsigned int nbABouger, Country *firstCountry, Country *secondCountry)
0066 {
0067   qCDebug(KSIRK_LOG) << "-> " << nbABouger ;
0068   KMessageParts messageParts;
0069 
0070   if (firstCountry-> nbArmies() <= nbABouger)
0071   {
0072     messageParts << I18N_NOOP("Cannot move %1 armies from %2 to %3") << QString::number(nbABouger)
0073       << firstCountry->name() << secondCountry->name();
0074     broadcastChangeItem(messageParts, ID_STATUS_MSG2, false);
0075     return false;
0076   }
0077   else
0078   {
0079     messageParts << I18N_NOOP("Moving %1 armies from %2 to %3") << QString::number(nbABouger) << firstCountry->name() << secondCountry->name();
0080     broadcastChangeItem(messageParts, ID_STATUS_MSG2);
0081   }
0082 
0083   AnimSpritesGroup* newGroup = new AnimSpritesGroup(this,SLOT(slotMovingArmiesArrived(AnimSpritesGroup*)));
0084   m_animSpritesGroups.push_back(newGroup);
0085   AnimSprite* sprite;
0086   if ((firstCountry-> nbArmies() > 10) && (nbABouger == 10)
0087           && (nbABouger < firstCountry-> nbArmies()))
0088   {
0089     sprite = new CannonSprite(m_theWorld->zoom(), backGnd(), 200);
0090     firstCountry-> decrNbArmies(10);
0091   }
0092   else if ((firstCountry-> nbArmies() > 5) && (nbABouger == 5)
0093           && (nbABouger < firstCountry-> nbArmies()))
0094   {
0095     sprite = new CavalrySprite(m_theWorld->zoom(), backGnd(), 200);
0096     firstCountry-> decrNbArmies(5);
0097   }
0098   else if ((firstCountry-> nbArmies() > 1) && (nbABouger == 1)
0099           && (nbABouger < firstCountry-> nbArmies()))
0100   {
0101     sprite = new InfantrySprite(m_theWorld->zoom(), backGnd(), 200);
0102     firstCountry->  decrNbArmies();
0103   }
0104   else 
0105   {
0106     messageParts << I18N_NOOP("Cannot move %1 armies from %2 to %3") 
0107       << QString::number(nbABouger) 
0108       << firstCountry->name() 
0109       << secondCountry->name();
0110     broadcastChangeItem(messageParts, ID_STATUS_MSG2, false);
0111     return false;
0112   }
0113   connect(sprite,&AnimSprite::atDestination,this,&KGameWindow::slotMovingArmyArrived);
0114   sprite->setupTravel(firstCountry, secondCountry);
0115   newGroup->addSprite(sprite);
0116   firstCountry-> createArmiesSprites();
0117   sprite->setAnimated();
0118 //   qCDebug(KSIRK_LOG) << "initArmiesMovement returns true";
0119   return true;
0120 }
0121 
0122 
0123 AnimSprite* KGameWindow::initArmiesMultipleCombat(unsigned int nbA,
0124     Country *firstCountry,
0125     Country *secondCountry, QPointF dest)
0126 {
0127   qCDebug(KSIRK_LOG) << "-> " << nbA ;
0128   KMessageParts messageParts;
0129 
0130   //AnimSpritesGroup* newGroup = new AnimSpritesGroup(this,SLOT(slotMovingArmiesArrived(AnimSpritesGroup*)));
0131   //m_animSpritesGroups.push_back(newGroup);
0132   AnimSprite* sprite = nullptr;
0133   if ((!firstCountry->spritesCannons().isEmpty()) && (nbA == 10))
0134   {
0135       qCDebug(KSIRK_LOG) << "cannon";
0136       sprite = new CannonSprite(m_theWorld->zoom(), backGnd(), 200);
0137 
0138     firstCountry->spritesCannons().hideAndRemoveFirst();
0139   }
0140   else if ((!firstCountry->spritesCavalry().isEmpty()) && (nbA == 5))
0141   {
0142       qCDebug(KSIRK_LOG) << "cavalry";
0143       sprite = new CavalrySprite(m_theWorld->zoom(), backGnd(), 200);
0144 
0145       firstCountry->spritesCavalry().hideAndRemoveFirst();
0146   }
0147   else if ((!firstCountry->spritesInfantry().isEmpty()) && (nbA == 1))
0148   {
0149     qCDebug(KSIRK_LOG) << "infantry";
0150     sprite = new InfantrySprite(m_theWorld->zoom(), backGnd(), 200);
0151 
0152     firstCountry->spritesInfantry().hideAndRemoveFirst();
0153   }
0154   // cannot comment out this comment below otherwise will use sprite uninitialized
0155   else
0156   {
0157     messageParts << I18N_NOOP("Cannot move %1 armies from %2 to %3") 
0158       << QString::number(nbA) 
0159       << firstCountry->name() 
0160       << secondCountry->name();
0161     broadcastChangeItem(messageParts, ID_STATUS_MSG2, false);
0162     return nullptr;
0163   }
0164   //connect(sprite,SIGNAL(atDestination(AnimSprite*)),this,SLOT(slotMovingArmyArrived(AnimSprite*)));
0165   
0166   if (backGnd()->bgIsArena())
0167   {
0168     int relativePosInArena=0;
0169 
0170     if (firstCountry->name() == secondCountry->name())
0171     {
0172       sprite->setDefendant();
0173       relativePosInArena = relativePosInArenaDefense;
0174       //relativePosInArenaDefense++;
0175     }
0176     else
0177     {
0178       sprite->setAttacker();
0179       relativePosInArena = relativePosInArenaAttack;
0180       //relativePosInArenaAttack++;
0181     }
0182 
0183     qCDebug(KSIRK_LOG) << "****Test relativePos**** " << relativePosInArena;
0184     QPointF dep = determinePointDepartArena(firstCountry,relativePosInArena);
0185 
0186     sprite-> setPos(dep);
0187 
0188     qCDebug(KSIRK_LOG) << "****dep  point**** " << dep;
0189     qCDebug(KSIRK_LOG) << "****dest point**** " << dest;
0190     sprite->setupTravel(firstCountry, secondCountry,dep,dest);
0191   }
0192   else
0193   {
0194     qCDebug(KSIRK_LOG) << "***************Setup travel normal ************** ";
0195     sprite->setupTravel(firstCountry, secondCountry,&dest);
0196   }
0197 
0198   qCDebug(KSIRK_LOG) << "-> "<< firstCountry->name() << secondCountry->name();
0199   //sprite->setupTravel(firstCountry, secondCountry,&dest);
0200   //newGroup->addSprite(sprite);
0201 //   qCDebug(KSIRK_LOG) << "add a sprite 1";
0202 //   m_animFighters->addSprite(sprite);
0203   //firstCountry-> createArmiesSprites();
0204   //sprite->setAnimated();
0205 //   qCDebug(KSIRK_LOG) << "initArmiesMovement returns true";
0206   return sprite;
0207 }
0208 
0209 
0210 QPointF KGameWindow::determinePointDepartArena(Country *pays, int relativePos)
0211 {
0212   return( QPointF(pays-> pointInfantry().x()*m_theWorld->zoom(),(pays-> pointInfantry().y()+(1-2*(relativePos%2))*(Sprites::SkinSpritesData::single().intData("infantry-height")+8)*((relativePos+1)/2))*m_theWorld->zoom()));
0213 }
0214 
0215 
0216 void KGameWindow::determinePointArrivee(
0217         QPointF& pointArriveeAttaquant,
0218         QPointF& pointArriveeDefenseur)
0219 {
0220   Country *attackingCountry = firstCountry();
0221   Country *defendingCountry = secondCountry();
0222   if (attackingCountry == nullptr || m_secondCountry == nullptr)
0223   {
0224     qCCritical(KSIRK_LOG) << "attackingCountry=" << (void*)attackingCountry << "defendingCountry=" << (void*)defendingCountry;
0225     return;
0226   }
0227   
0228   //  - attacker's flag point
0229   qreal pointFlagAttaquantX = attackingCountry-> pointFlag().x()*m_theWorld->zoom();
0230 
0231   //  - defender's flag point
0232   qreal pointFlagDefenseurX;
0233   pointFlagDefenseurX = defendingCountry-> pointFlag().x()*m_theWorld->zoom();
0234   
0235   //  - attacker's arrival point (resp. defender's) (left or right of the
0236   //    defender's flag point depending on the attacker's flag point position)
0237   qreal pointArriveeAttaquantX;
0238   qreal pointArriveeY;
0239   qreal pointArriveeDefenseurX;
0240   qreal pointDepartAttaquantX;
0241   qreal pointDepartDefenseurX;
0242   qreal pointDepartAttaquantY;
0243   qreal pointDepartDefenseurY;
0244   qreal leftRelativePos;
0245 
0246   if (!attackingCountry->spritesInfantry().isEmpty())
0247   {
0248     // We must know
0249     //  - attacker's departure point (pointInfantry)
0250     pointDepartAttaquantX = attackingCountry-> pointInfantry().x()*m_theWorld->zoom();
0251     pointDepartAttaquantY = attackingCountry-> pointInfantry().y()*m_theWorld->zoom();
0252   }
0253   else if (!attackingCountry->spritesCavalry().isEmpty())
0254   {
0255     // We must know
0256     //  - attacker's departure point (pointCavalry)
0257     pointDepartAttaquantX = attackingCountry-> pointCavalry().x()*m_theWorld->zoom();
0258     pointDepartAttaquantY = attackingCountry-> pointCavalry().y()*m_theWorld->zoom();
0259   }
0260   else
0261   {
0262     // We must know
0263     //  - attacker's departure point (pointCannon)
0264       pointDepartAttaquantX = attackingCountry-> pointCannon().x()*m_theWorld->zoom();
0265       pointDepartAttaquantY = attackingCountry-> pointCannon().y()*m_theWorld->zoom();
0266   }
0267 
0268   if (!defendingCountry->spritesInfantry().isEmpty())
0269   {
0270     //  - defender's departure point (pointInfantry)
0271     pointDepartDefenseurX = defendingCountry-> pointInfantry().x()*m_theWorld->zoom();
0272     pointDepartDefenseurY = defendingCountry-> pointInfantry().y()*m_theWorld->zoom();
0273   
0274   }
0275   else if (!defendingCountry->spritesCavalry().isEmpty())
0276   {
0277     //  - defender's departure point (pointCavalry)
0278     pointDepartDefenseurX = defendingCountry-> pointCavalry().x()* m_theWorld->zoom();
0279     pointDepartDefenseurY = defendingCountry-> pointCavalry().y()* m_theWorld->zoom();
0280   }
0281   else
0282   {
0283     //  - defender's departure point (pointCannon)
0284     pointDepartDefenseurX = defendingCountry-> pointCannon().x()*  m_theWorld->zoom();
0285     pointDepartDefenseurY = defendingCountry-> pointCannon().y()*  m_theWorld->zoom();
0286   }
0287 
0288   // vertical meet point
0289   int diff = Sprites::SkinSpritesData::single().intData("flag-height") - Sprites::SkinSpritesData::single().intData("cannon-height");
0290   pointArriveeY = (((defendingCountry-> pointFlag().y() + diff))* m_theWorld->zoom()) ;
0291   
0292   qCDebug(KSIRK_LOG) << "2 " << defendingCountry-> pointFlag().y() << pointArriveeY;
0293   if (!attackingCountry->communicateWith(defendingCountry))
0294   {
0295     qCCritical(KSIRK_LOG) << "Error in KGameWindow::determinePointDepartArena: " << attackingCountry-> name() << "  and "
0296             << defendingCountry-> name() << " do not communicate!";
0297     exit(2);
0298   }
0299   
0300   // If the flag of the attacker is to the left of the flag of the defender,
0301   // then the arriving point of the attacker is to the left, else it is to
0302   // the right
0303   // The situation is reversed if the one of the attacker will need to go
0304   // through the world limit
0305   if (!attackingCountry->spritesInfantry().isEmpty())
0306   {
0307     leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("infantry-width"))*m_theWorld->zoom();
0308   }
0309   else
0310   {
0311     if (!attackingCountry->spritesCavalry().isEmpty())
0312     {
0313       leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("cavalry-width"))*m_theWorld->zoom();
0314     }
0315     else
0316     {
0317       leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("cannon-width"))*m_theWorld->zoom();
0318     }
0319   }
0320   
0321   qreal rightRelativePos = (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("flag-width"))*m_theWorld->zoom();
0322 
0323   if (!(qAbs(pointFlagAttaquantX-pointFlagDefenseurX) > (backGnd()-> boundingRect().width() / 2)))
0324   {
0325     if ( pointFlagAttaquantX <= pointFlagDefenseurX )
0326     {
0327         pointArriveeAttaquantX = pointFlagDefenseurX + leftRelativePos;
0328         pointArriveeDefenseurX = pointFlagDefenseurX + rightRelativePos;
0329     }
0330     else
0331     {
0332         pointArriveeAttaquantX = pointFlagDefenseurX + rightRelativePos;
0333         pointArriveeDefenseurX = pointFlagDefenseurX + leftRelativePos;
0334     }
0335   }
0336   else
0337   {
0338     if ( pointFlagAttaquantX <= pointFlagDefenseurX )
0339     {
0340         pointArriveeAttaquantX = pointFlagDefenseurX + rightRelativePos;
0341         pointArriveeDefenseurX = pointFlagDefenseurX + leftRelativePos;
0342     }
0343     else
0344     {
0345         pointArriveeAttaquantX = pointFlagDefenseurX +leftRelativePos;
0346         pointArriveeDefenseurX = pointFlagDefenseurX + rightRelativePos;
0347     }
0348   }
0349 
0350   pointArriveeAttaquant.setX(pointArriveeAttaquantX);
0351   pointArriveeAttaquant.setY(pointArriveeY);
0352   pointArriveeDefenseur.setX(pointArriveeDefenseurX);
0353   pointArriveeDefenseur.setY(pointArriveeY);
0354   qCDebug(KSIRK_LOG) << "3: " << pointArriveeAttaquant << " ; " << pointArriveeDefenseur;
0355 }
0356 
0357 
0358 // point arriveedefenseur inutile
0359 void KGameWindow::determinePointArriveeForArena(
0360     int relative,
0361     QPointF& pointArriveeAttaquant,
0362     QPointF& pointArriveeDefenseur)
0363 {
0364   Country *attackingCountry = firstCountry();
0365   Country *defendingCountry = secondCountry();
0366   
0367   qCDebug(KSIRK_LOG) << m_firstCountry->name() << "("<<(void*)m_firstCountry<<")"
0368       << m_secondCountry->name() << "("<<(void*)m_secondCountry<<")";
0369   qCDebug(KSIRK_LOG) << attackingCountry->name() << "("<<(void*)attackingCountry<<")"
0370       << defendingCountry->name() << "("<<(void*)defendingCountry<<")"
0371       << relative << pointArriveeAttaquant << pointArriveeDefenseur;
0372   //  - attacker's flag point
0373   qreal pointFlagAttaquantX = attackingCountry-> pointFlag().x()*m_theWorld->zoom();
0374 
0375   // in case of arena, the meet will be between the two countries
0376   qreal pointFlagDefenseurX = backGnd()-> boundingRect().width() / 2;
0377   
0378   //  - attacker's arrival point (resp. defender's) (left or right of the
0379   //    defender's flag point depending on the attacker's flag point position)
0380   qreal pointArriveeAttaquantX;
0381   qreal pointArriveeY;
0382   qreal pointArriveeDefenseurX;
0383   qreal pointDepartAttaquantX;
0384   qreal pointDepartDefenseurX;
0385   qreal pointDepartAttaquantY;
0386   qreal pointDepartDefenseurY;
0387   qreal leftRelativePos;
0388 
0389   qCDebug(KSIRK_LOG) << "1" << attackingCountry->spritesInfantry().isEmpty()
0390   << attackingCountry->name()
0391   << attackingCountry->nbArmies()
0392   << attackingCountry->owner()->name()
0393   << ((attackingCountry->name()==m_firstCountry->name())?attackingCountry->owner()->getNbAttack():attackingCountry->owner()->getNbDefense());
0394   
0395   if ( attackingCountry->nbArmies()%5 != 0
0396     && ((attackingCountry->nbArmies() % 5) >= ((attackingCountry->name()==m_firstCountry->name())?attackingCountry->owner()->getNbAttack():attackingCountry->owner()->getNbDefense())))
0397 //   if (!attackingCountry->spritesInfantry().isEmpty()
0398 //       && ((attackingCountry->nbArmies() % 5) >= ((attackingCountry==m_firstCountry)?attackingCountry->owner()->getNbAttack():attackingCountry->owner()->getNbDefense())))
0399       {
0400     qCDebug(KSIRK_LOG) << "infantry" << attackingCountry->name() << relative;
0401     // We must know
0402     //  - attacker's departure point (pointInfantry)
0403     QPointF dep = determinePointDepartArena(attackingCountry, relative);
0404     qCDebug(KSIRK_LOG) << "dep=" << dep;
0405     pointDepartAttaquantX = dep.x();
0406     pointDepartAttaquantY = dep.y();
0407   }
0408   else if (!attackingCountry->spritesCavalry().isEmpty())
0409   {
0410     qCDebug(KSIRK_LOG) << "cavalry" << attackingCountry->pointCavalry();
0411     // We must know
0412     //  - attacker's departure point (pointCavalry)
0413     pointDepartAttaquantX = attackingCountry-> pointCavalry().x()*m_theWorld->zoom();
0414     pointDepartAttaquantY = attackingCountry-> pointCavalry().y()*m_theWorld->zoom();
0415   }
0416   else
0417   {
0418     qCDebug(KSIRK_LOG) << "cannon" << attackingCountry->pointCannon();
0419     // We must know
0420     //  - attacker's departure point (pointCannon)
0421       pointDepartAttaquantX = attackingCountry-> pointCannon().x()*m_theWorld->zoom();
0422       pointDepartAttaquantY = attackingCountry-> pointCannon().y()*m_theWorld->zoom();
0423   }
0424 
0425   // problem here: when handling defender, attacker sprites are already moving so
0426   // if it has no more infantry sprites, it will not be able to enter this loop
0427   // solution: use the number of armies (equivalent to the number of stationary
0428   // sprites) and not the number of infantry sprites
0429   // defendingCountry->spritesInfantry().isEmpty() === (defendingCountry->nbArmies()%5==0)
0430   unsigned int num = 0;
0431   if (defendingCountry->name()==m_firstCountry->name())
0432   {
0433     num = defendingCountry->owner()->getNbAttack();
0434   }
0435   else
0436   {
0437     num = defendingCountry->owner()->getNbDefense();
0438   }
0439   qCDebug(KSIRK_LOG) << "2"
0440     << defendingCountry->spritesInfantry().isEmpty()
0441     << defendingCountry->name()
0442     << defendingCountry->nbArmies()
0443     << defendingCountry->owner()->name()
0444     << num;
0445   if ( defendingCountry->nbArmies()%5 != 0
0446       && ((defendingCountry->nbArmies() % 5) >= num)
0447       )
0448 //   if (!defendingCountry->spritesInfantry().isEmpty()
0449 //       && ((defendingCountry->nbArmies() % 5) >= defendingCountry->owner()->getNbDefense()))
0450   {
0451     qCDebug(KSIRK_LOG) << "infantry" << defendingCountry->name() << relative;
0452     //  - defender's departure point (pointInfantry)
0453     QPointF dep = determinePointDepartArena(defendingCountry, relative);
0454     pointDepartDefenseurX = dep.x();
0455     pointDepartDefenseurY = dep.y();
0456     qCDebug(KSIRK_LOG) << "dep=" << dep;
0457   }
0458   else if (!defendingCountry->spritesCavalry().isEmpty())
0459   {
0460     qCDebug(KSIRK_LOG) << "cavalry" << defendingCountry->pointCavalry();
0461     //  - defender's departure point (pointCavalry)
0462     pointDepartDefenseurX = defendingCountry-> pointCavalry().x()*m_theWorld->zoom();
0463     pointDepartDefenseurY = defendingCountry-> pointCavalry().y()*m_theWorld->zoom();
0464   }
0465   else
0466   {
0467     qCDebug(KSIRK_LOG) << "cannon" << defendingCountry->pointCannon();
0468     //  - defender's departure point (pointCannon)
0469     pointDepartDefenseurX = defendingCountry-> pointCannon().x()*m_theWorld->zoom();
0470     pointDepartDefenseurY = defendingCountry-> pointCannon().y()*m_theWorld->zoom();
0471   }
0472 
0473 
0474   // vertical meet point
0475   // in case of arena, the vertical meet will be as soon as it's possible
0476   qCDebug(KSIRK_LOG) << "Argh " << pointDepartAttaquantY << pointDepartDefenseurY;
0477   pointArriveeY = (pointDepartAttaquantY+pointDepartDefenseurY)/2;
0478   
0479   if (!attackingCountry->communicateWith(defendingCountry))
0480   {
0481     qCCritical(KSIRK_LOG) << "Error in KGameWindow::determinePointArriveeForArena: " << attackingCountry-> name() << "  and "
0482             << defendingCountry-> name() << " do not communicate!";
0483     exit(2);
0484   }
0485   // If the flag of the attacker is to the left of the flag of the defender,
0486   // then the arriving point of the attacker is to the left, else it is to
0487   // the right
0488   // The situation is reversed if the one of the attacker will need to go
0489   // through the world limit
0490 
0491   qreal factor = 0;
0492   if (!attackingCountry->spritesInfantry().isEmpty()
0493     && ((attackingCountry->nbArmies() % 5) >= attackingCountry->owner()->getNbAttack()))
0494   {
0495     factor = Sprites::SkinSpritesData::single().intData("infantry-width");
0496   }
0497   else if (!attackingCountry->spritesCavalry().isEmpty())
0498   {
0499     factor = Sprites::SkinSpritesData::single().intData("cavalry-width");
0500   }
0501   else
0502   {
0503     factor = Sprites::SkinSpritesData::single().intData("cannon-width");
0504   }
0505   leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + factor)*m_theWorld->zoom();
0506 
0507   
0508   qreal rightRelativePos = (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("flag-width"))*m_theWorld->zoom();
0509 
0510   //if (!(qAbs(pointFlagAttaquantX-pointFlagDefenseurX) > (backGnd()-> boundingRect().width() / 2)) || backGnd()->bgIsArena())
0511   //{
0512   if ( pointFlagAttaquantX <= pointFlagDefenseurX )
0513   {
0514       pointArriveeAttaquantX = pointFlagDefenseurX + leftRelativePos;
0515       pointArriveeDefenseurX = pointFlagDefenseurX + rightRelativePos;
0516   }
0517   else
0518   {
0519       pointArriveeAttaquantX = pointFlagDefenseurX + rightRelativePos;
0520       pointArriveeDefenseurX = pointFlagDefenseurX + leftRelativePos;
0521   }
0522 
0523   pointArriveeAttaquant.setX(pointArriveeAttaquantX);
0524   pointArriveeAttaquant.setY(pointArriveeY);
0525   pointArriveeDefenseur.setX(pointArriveeDefenseurX);
0526   pointArriveeDefenseur.setY(pointArriveeY);
0527   qCDebug(KSIRK_LOG) << "Done: " << pointArriveeAttaquant << " ; " << pointArriveeDefenseur;
0528 }
0529 
0530 
0531 void KGameWindow::initCombatMovement()
0532 {
0533   qCDebug(KSIRK_LOG) << "1";
0534 
0535   Country *attackingCountry = firstCountry();
0536   Country *defendingCountry = secondCountry();
0537   if (attackingCountry == nullptr || defendingCountry == nullptr)
0538   {
0539     qCCritical(KSIRK_LOG) << "attackingCountry=" << (void*)attackingCountry << "defendingCountry=" << (void*)defendingCountry;
0540     return;
0541   }
0542   
0543   getRightDialog()->close();
0544   if (firstCountry() != nullptr && firstCountry()->owner() != nullptr 
0545     && secondCountry() != nullptr && secondCountry()->owner() != nullptr)
0546   {
0547     getRightDialog()->displayFightDetails(firstCountry(), secondCountry(),
0548         firstCountry()->owner()->getNbAttack(), secondCountry()->owner()->getNbDefense());
0549   }
0550   centerOnFight();  //center the game on the fight
0551   if  (isArena()
0552       && ! m_automaton->currentPlayer()->isAI()
0553       && !m_automaton->currentPlayer()->isVirtual())
0554   {
0555     qCDebug(KSIRK_LOG) << "Attack with arena";
0556     // init and display the arena view
0557     showArena();
0558   }
0559 
0560   m_animFighters->clear();
0561   m_animFighters->changeTarget(this,SLOT(slotMovingFightersArrived(AnimSpritesGroup*)));
0562 
0563   QString sndRoulePath;
0564   AnimSprite* defenderSprite = nullptr;
0565   AnimSprite* attackingSprite = nullptr;
0566 
0567   QPointF pointArriveeAttaquant(0,0);
0568   QPointF pointArriveeDefenseur(0,0);
0569  
0570   if (backGnd()->bgIsArena())
0571   {
0572     determinePointArriveeForArena(0,
0573         pointArriveeAttaquant, pointArriveeDefenseur);
0574   }
0575   else
0576   {
0577     determinePointArrivee(pointArriveeAttaquant, pointArriveeDefenseur);
0578   }
0579 
0580   if (!attackingCountry->spritesInfantry().isEmpty()
0581       && ((attackingCountry->nbArmies() % 5) >= attackingCountry->owner()->getNbAttack())
0582       && backGnd()->bgIsArena())
0583   {
0584     qCDebug(KSIRK_LOG) << "**NB-ATTACK**" << attackingCountry->owner()->getNbAttack();
0585 
0586     for (unsigned int i=0; i < attackingCountry->owner()->getNbAttack() ; i++)
0587     {
0588       attackingSprite = simultaneousAttack(1,KGameWindow::Attack);
0589       if (attackingSprite != nullptr)
0590       {
0591         qCDebug(KSIRK_LOG) << "add a sprite";
0592         m_animFighters->addSprite(attackingSprite);
0593       }
0594     }
0595     nbSpriteAttacking=attackingCountry->owner()->getNbAttack();
0596   }
0597   else
0598   {
0599     qCDebug(KSIRK_LOG) << "creating attackingSprite"
0600               << attackingCountry->name()
0601               << attackingCountry->nbArmies()
0602               << attackingCountry->spritesInfantry().size()
0603               << attackingCountry->spritesCavalry().size()
0604               << attackingCountry->spritesCannons().size();
0605     nbSpriteAttacking=1;
0606     if ( (attackingCountry->nbArmies() != 0)
0607       && attackingCountry->spritesInfantry().isEmpty()
0608       && attackingCountry->spritesCavalry().isEmpty()
0609       && attackingCountry->spritesCannons().isEmpty())
0610     {
0611       attackingCountry->createArmiesSprites();
0612     }
0613     if (!attackingCountry->spritesCavalry().isEmpty())
0614     {
0615       qCDebug(KSIRK_LOG) << "cavalry" << backGnd()->bgIsArena();
0616       if (backGnd()->bgIsArena())
0617       {
0618         attackingSprite = simultaneousAttack(5,KGameWindow::Attack);
0619       }
0620       else
0621       {
0622         attackingSprite = new CavalrySprite(m_theWorld->zoom(), backGnd(), 200);
0623 
0624         attackingCountry->spritesCavalry().hideAndRemoveFirst();
0625       }
0626     }
0627     else if (!attackingCountry->spritesCannons().isEmpty())
0628     {
0629       qCDebug(KSIRK_LOG) << "cannon" << backGnd()->bgIsArena();
0630       if (backGnd()->bgIsArena())
0631       {
0632         attackingSprite = simultaneousAttack(10,KGameWindow::Attack);
0633       }
0634       else
0635       {
0636         attackingSprite = new CannonSprite(m_theWorld->zoom(), backGnd(), 200);
0637 
0638         attackingCountry->spritesCannons().hideAndRemoveFirst();
0639       }
0640     }
0641     else if (!attackingCountry->spritesInfantry().isEmpty())
0642     {
0643       qCDebug(KSIRK_LOG) << "infantry" << backGnd()->bgIsArena();
0644       if (backGnd()->bgIsArena())
0645       {
0646         attackingSprite = simultaneousAttack(1,KGameWindow::Attack);
0647       }
0648       else
0649       {
0650         attackingSprite = new InfantrySprite(m_theWorld->zoom(), backGnd(), 200);
0651 
0652         attackingCountry->spritesInfantry().hideAndRemoveFirst();
0653       }
0654     }
0655     else 
0656     {
0657       qCDebug(KSIRK_LOG) << "No sprite on attacking country!";
0658       assert(false);
0659     }
0660 
0661     if (attackingSprite == nullptr)
0662     {
0663       qCCritical(KSIRK_LOG) << "ERROR: null attackingSprite at " << __FILE__ << ", line " << __LINE__;
0664 //       return;
0665     }
0666     else
0667     {
0668       qCDebug(KSIRK_LOG) << "attackingSprite created";
0669 
0670       // Adding the number of attackers decoration
0671       if (attackingCountry->owner()->getNbAttack() == 1)
0672       {
0673         attackingSprite->addDecoration("mark1", QRect(0,0,10,10));
0674       }
0675       else if (attackingCountry->owner()->getNbAttack() == 2)
0676       {
0677         attackingSprite->addDecoration("mark2", QRect(0,0,10,10));
0678       }
0679       else
0680       {
0681         attackingSprite->addDecoration("mark3", QRect(0,0,10,10));
0682       }
0683 
0684       attackingSprite-> setAttacker();
0685       attackingSprite->setupTravel(attackingCountry, defendingCountry, &pointArriveeAttaquant);
0686       qCDebug(KSIRK_LOG) << "add a sprite 2";
0687       m_animFighters->addSprite(attackingSprite);
0688       //(pointDepartAttaquantX <= pointArriveeAttaquantX) ? attackingSprite-> setLookRight() : attackingSprite-> setLookLeft();
0689       sndRoulePath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/roll.wav");
0690       if (sndRoulePath.isNull())
0691       {
0692         KMessageBox::error(nullptr, i18n("Sound roule not found - Verify your installation<br>Program cannot continue"), i18n("Error!"));
0693         exit(2);
0694       }
0695       if (KsirkSettings::soundEnabled())
0696       {
0697         m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndRoulePath));
0698         m_audioPlayer->play();
0699       }
0700     }
0701   }
0702 
0703   if (!defendingCountry->spritesInfantry().isEmpty()
0704     && ((defendingCountry->nbArmies() % 5) >= defendingCountry->owner()->getNbDefense())
0705     && backGnd()->bgIsArena())
0706   {
0707     qCDebug(KSIRK_LOG) << "**NB-DEFENSE**" << defendingCountry->owner()->getNbDefense();
0708 
0709     for (unsigned int i=0;i< defendingCountry->owner()->getNbDefense();i++)
0710     {
0711       defenderSprite = simultaneousAttack(1,KGameWindow::Defense);
0712       if (defenderSprite != nullptr)
0713       {
0714         qCDebug(KSIRK_LOG) << "add a sprite";
0715         m_animFighters->addSprite(defenderSprite);
0716       }
0717     }
0718     nbSpriteDefending=defendingCountry->owner()->getNbDefense();
0719   }
0720   else
0721   {
0722     qCDebug(KSIRK_LOG) << "creating defenderSprite" << defendingCountry->name()
0723               << defendingCountry->nbArmies()
0724               << defendingCountry->spritesInfantry().size()
0725               << defendingCountry->spritesCavalry().size()
0726               << defendingCountry->spritesCannons().size();
0727     nbSpriteDefending=1;
0728     if ( (defendingCountry->nbArmies() != 0) 
0729       && defendingCountry->spritesInfantry().isEmpty()
0730       && defendingCountry->spritesCavalry().isEmpty()
0731       && defendingCountry->spritesCannons().isEmpty())
0732     {
0733       defendingCountry->createArmiesSprites();
0734     }
0735     if (!defendingCountry->spritesCavalry().isEmpty())
0736     {
0737       qCDebug(KSIRK_LOG) << "cavalry" << backGnd()->bgIsArena();
0738       if (backGnd()->bgIsArena())
0739       {
0740         defenderSprite = simultaneousAttack(5,KGameWindow::Defense);
0741       }
0742       else
0743       {
0744         defenderSprite = new CavalrySprite(m_theWorld->zoom(), backGnd(), 200);
0745 
0746         defendingCountry->spritesCavalry().hideAndRemoveFirst();
0747       }
0748     }
0749     else if (!defendingCountry->spritesCannons().isEmpty())
0750     {
0751       qCDebug(KSIRK_LOG) << "cannon" << backGnd()->bgIsArena();
0752       if (backGnd()->bgIsArena())
0753       {
0754         defenderSprite = simultaneousAttack(10,KGameWindow::Defense);
0755       }
0756       else
0757       {
0758         defenderSprite = new CannonSprite(m_theWorld->zoom(), backGnd(), 200);
0759 
0760         defendingCountry->spritesCannons().hideAndRemoveFirst();
0761       }
0762     }
0763     else if (!defendingCountry->spritesInfantry().isEmpty())
0764     {
0765       qCDebug(KSIRK_LOG) << "infantry" << backGnd()->bgIsArena();
0766       if (backGnd()->bgIsArena())
0767       {
0768         defenderSprite = simultaneousAttack(1,KGameWindow::Defense);
0769       }
0770       else
0771       {
0772         defenderSprite = new InfantrySprite(m_theWorld->zoom(), backGnd(), 200);
0773 
0774         defendingCountry->spritesInfantry().hideAndRemoveFirst();
0775       }
0776     }
0777     else
0778     {
0779       qCCritical(KSIRK_LOG) << "No sprite on defending country" << defendingCountry->name();
0780       return;
0781     }
0782 
0783     if (defenderSprite==nullptr)
0784     {
0785       qCCritical(KSIRK_LOG) << "ERROR: null defenderSprite at " << __FILE__ << ", line " << __LINE__;
0786       return;
0787     }
0788     else
0789     {
0790       if (defendingCountry->owner()->getNbDefense() == 1)
0791       {
0792         defenderSprite->addDecoration("mark1", QRect(0,0,10,10));
0793       }
0794       else if (defendingCountry->owner()->getNbDefense() == 2)
0795       {
0796         defenderSprite->addDecoration("mark2", QRect(0,0,10,10));
0797       }
0798 
0799       defenderSprite-> setDefendant();
0800       defenderSprite-> setupTravel(defendingCountry, defendingCountry, &pointArriveeDefenseur);
0801       //(pointDepartDefenseurX <= pointArriveeDefenseurX) ? defenderSprite-> setLookRight() : defenderSprite-> setLookLeft();
0802       qCDebug(KSIRK_LOG) << "add a sprite 3";
0803       m_animFighters->addSprite(defenderSprite);
0804       sndRoulePath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/roll.wav");
0805       if (sndRoulePath.isNull())
0806       {
0807         KMessageBox::error(nullptr, i18n("Sound roule not found - Verify your installation<br>Program cannot continue"), i18n("Error!"));
0808         exit(2);
0809       }
0810       if (KsirkSettings::soundEnabled())
0811       {
0812         m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndRoulePath));
0813         m_audioPlayer->play();
0814       }
0815     }
0816   }
0817   qCDebug(KSIRK_LOG) << "Done";
0818 }
0819 
0820 void KGameWindow::animCombat()
0821 {
0822   qCDebug(KSIRK_LOG);
0823   m_animFighters->changeTarget(this, SLOT(slotFiringFinished(AnimSpritesGroup*)));
0824 
0825   AnimSpritesGroup::iterator it, it_end;
0826   it = m_animFighters->begin(); it_end = m_animFighters->end();
0827   for (; it != it_end; it++)
0828   {
0829     qCDebug(KSIRK_LOG) << "a sprite position: " << (*it)->pos();
0830     AnimSprite* sprite = (*it);
0831     sprite-> changeSequence("firing");
0832 
0833     qreal firingRelativePos = (Sprites::SkinSpritesData::single().intData("cannon-width") - Sprites::SkinSpritesData::single().intData("firing-width"))*m_theWorld->zoom();
0834     if (sprite-> looksToLeft()) 
0835     {
0836       sprite-> setPos(
0837         sprite-> x() + firingRelativePos,
0838         sprite-> y() );
0839     }
0840     else
0841     {
0842       sprite-> setPos(
0843       sprite-> x() + firingRelativePos,
0844                       sprite-> y() );
0845     }
0846     sprite->setAnimated(1);
0847 
0848     QString sndCanonPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/cannon.wav");
0849     if (sndCanonPath.isNull())
0850     {
0851       KMessageBox::error(nullptr,
0852           i18n("Sound cannon not found - Verify your installation<br>Program cannot continue"), i18n("Error!"));
0853       exit(2);
0854     }
0855     if (KsirkSettings::soundEnabled())
0856     {
0857       m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCanonPath));
0858       m_audioPlayer->play();
0859     }
0860   }
0861 }
0862 
0863 // not currently in use
0864 void KGameWindow::stopCombat()
0865 {
0866 /*
0867 //   qCDebug(KSIRK_LOG);
0868   AnimSpritesGroup::iterator it = m_animFighters->begin();
0869   while (it != m_animFighters->end())
0870   {
0871     CannonSprite* sprite = (CannonSprite*)(*it);
0872 //     it = m_animFighters.remove(it);
0873     sprite-> changeSequence("cannon");
0874 
0875     if (sprite-> looksToLeft()) 
0876     {
0877       sprite-> setPos(
0878         sprite->x() + (Sprites::SkinSpritesData::single().intData("cannon-width"))*m_theWorld->zoom(),
0879         sprite-> y() );
0880     }
0881     else 
0882     {
0883 //       sprite-> setX(sprite-> x());
0884     }
0885   }*/
0886 }
0887 
0888 
0889 void KGameWindow::animExplosion(int who)
0890 {
0891   qCDebug(KSIRK_LOG) << who;
0892   Country *attackingCountry = firstCountry();
0893   
0894   m_animFighters->changeTarget(this, SLOT(slotExplosionFinished(AnimSpritesGroup*)));
0895 
0896   qCDebug(KSIRK_LOG) << m_animFighters->size() << " fighters";
0897   unsigned int toArrive = 0;
0898   AnimSpritesGroup::iterator it = m_animFighters->begin();
0899   for (;it != m_animFighters->end();it++)
0900   {
0901     AnimSprite* sprite = (AnimSprite*)(*it);
0902     if ( (who == 2) // both are killed
0903         || ((who == 0) && (sprite-> isAttacker()))  // Attacker is killed
0904         || ((who == 1) && (sprite-> isDefendant())) ) // Defender is killed
0905     {
0906       sprite-> changeSequence("exploding");
0907 
0908       qreal firingRelativePos = (Sprites::SkinSpritesData::single().intData("firing-width") - Sprites::SkinSpritesData::single().intData("exploding-width"))*m_theWorld->zoom();
0909       if (sprite-> looksToLeft())
0910       {
0911         sprite-> setPos(
0912           sprite-> x() + firingRelativePos,
0913           sprite-> y() );
0914       }
0915 
0916       if (sprite->isAttacker())
0917       {
0918         qCDebug(KSIRK_LOG) << "  removing a sprite";
0919         //qCDebug(KSIRK_LOG) << "i attack" << i;
0920         qCDebug(KSIRK_LOG) << "NKA" << NKA;
0921 
0922         sprite->setAnimated(NKA);
0923 
0924         QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
0925         if (sndCrashPath.isNull())
0926         {
0927           KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
0928           exit(2);
0929         }
0930         if (KsirkSettings::soundEnabled())
0931         {
0932           m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
0933           m_audioPlayer->play();
0934         }
0935       }
0936 
0937       if (sprite->isDefendant())
0938       {
0939         qCDebug(KSIRK_LOG) << "  removing a sprite";
0940         qCDebug(KSIRK_LOG) << "NKD" << NKD;
0941 
0942         sprite->setAnimated(NKD);
0943 
0944         QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
0945         if (sndCrashPath.isNull())
0946         {
0947           KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
0948           exit(2);
0949         }
0950         if (KsirkSettings::soundEnabled())
0951         {
0952           m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
0953           m_audioPlayer->play();
0954         }
0955       }
0956     }
0957     else  // the sprite is not the one (or one the several) killed
0958     {
0959       qCDebug(KSIRK_LOG) << "  keeping a sprite";
0960       
0961       if ((attackingCountry->nbArmies() % 10) == 0)
0962       {
0963         sprite-> changeSequence("cannon");
0964       }
0965       else if ((attackingCountry->nbArmies() % 5) == 0)
0966       {
0967         sprite-> changeSequence("cavalry");
0968       }
0969       else
0970       {
0971         sprite-> changeSequence("infantry");
0972       }
0973 
0974       sprite->setStatic();
0975       toArrive++;
0976     }
0977   }
0978   for (unsigned int i=0; i < toArrive; i++)
0979   {
0980     m_animFighters->oneArrived(nullptr);
0981   }
0982   qCDebug(KSIRK_LOG) << "loop done";
0983 
0984   /*QString sndCrashPath = m_dirs-> findResource("appdata", m_automaton->skin() + "/Sounds/crash.wav");
0985   if (sndCrashPath.isNull())
0986   {
0987     KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
0988     exit(2);
0989   }
0990   if (KsirkSettings::soundEnabled())
0991   {
0992     m_audioPlayer->setCurrentSource(sndCrashPath);
0993     m_audioPlayer->play();
0994   }*/
0995   qCDebug(KSIRK_LOG) << "finished";
0996 //   m_frame-> initTimer();
0997 //    qCDebug(KSIRK_LOG)<<"OUT";
0998 }
0999 
1000 
1001 void KGameWindow::animExplosionForArena()
1002 {
1003   qCDebug(KSIRK_LOG);
1004 
1005   Country *attackingCountry = firstCountry();
1006   Country *defendingCountry = secondCountry();
1007 
1008   m_animFighters->changeTarget(this, SLOT(slotExplosionFinished(AnimSpritesGroup*)));
1009 
1010   qCDebug(KSIRK_LOG) << "hidden; " << m_animFighters->size() << " fighters";
1011   AnimSpritesGroup::iterator it = m_animFighters->begin();
1012   
1013   int nbAttackerSurvivor=attackingCountry->owner()->getNbAttack()-NKA;
1014   int nbDefenderSurvivor=defendingCountry->owner()->getNbDefense()-NKD;
1015 
1016   qCDebug(KSIRK_LOG) << "nbAttackerSurvivor" << nbAttackerSurvivor;
1017   qCDebug(KSIRK_LOG) << "nbDefenderSurvivor" << nbDefenderSurvivor;
1018   qCDebug(KSIRK_LOG) << "nbSpriteAttacking" << nbSpriteAttacking;
1019   qCDebug(KSIRK_LOG) << "nbSpriteDefending" << nbSpriteDefending;
1020 
1021   for (int nbSpriteTreated=0;
1022       (nbSpriteTreated < nbSpriteAttacking)&&(it!=m_animFighters->end());
1023       it++,nbSpriteTreated++)
1024   {
1025     AnimSprite* sprite = (AnimSprite*)(*it);
1026 
1027     qCDebug(KSIRK_LOG) << "nbSpriteTreated" << nbSpriteTreated;
1028 
1029     if(dynamic_cast<CannonSprite*>(sprite) != nullptr)
1030     {
1031       qCDebug(KSIRK_LOG) << "*******CANNON*******";
1032 
1033       if (NKA>0)
1034       {
1035         sprite-> changeSequence("exploding");
1036 
1037         if (sprite->isAttacker())
1038         {
1039           qCDebug(KSIRK_LOG) << "  removing a sprite";
1040           //qCDebug(KSIRK_LOG) << "i attack" << i;
1041           qCDebug(KSIRK_LOG) << "NKA" << NKA;
1042 
1043           sprite->setAnimated(NKA);
1044 
1045           QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
1046           if (sndCrashPath.isNull())
1047           {
1048             KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
1049             exit(2);
1050           }
1051           if (KsirkSettings::soundEnabled())
1052           {
1053             m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
1054             m_audioPlayer->play();
1055           }
1056         }
1057       }
1058       else
1059       {
1060         sprite-> changeSequence("cannon");
1061 
1062         sprite->setStatic();
1063         m_animFighters->oneArrived(nullptr);
1064       }
1065     }
1066     else if(dynamic_cast<CavalrySprite*>(sprite) != nullptr)
1067     {
1068       qCDebug(KSIRK_LOG) << "*******CAVALIER*******";
1069 
1070       if (NKA>0)
1071       {
1072         sprite-> changeSequence("exploding");
1073 
1074         if (sprite->isAttacker())
1075         {
1076           qCDebug(KSIRK_LOG) << "  removing a sprite";
1077           //qCDebug(KSIRK_LOG) << "i attack" << i;
1078           qCDebug(KSIRK_LOG) << "NKA" << NKA;
1079 
1080           sprite->setAnimated(NKA);
1081 
1082           QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
1083           if (sndCrashPath.isNull())
1084           {
1085             KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
1086             exit(2);
1087           }
1088           if (KsirkSettings::soundEnabled())
1089           {
1090             m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
1091             m_audioPlayer->play();
1092           }
1093         }
1094       }
1095       else
1096       {
1097         sprite-> changeSequence("cavalry");
1098 
1099         sprite->setStatic();
1100         m_animFighters->oneArrived(nullptr);
1101       }
1102     }
1103     else
1104     {
1105       if (nbAttackerSurvivor<=0)
1106       {
1107         sprite-> changeSequence("exploding");
1108 
1109         if (sprite->isAttacker())
1110         {
1111           qCDebug(KSIRK_LOG) << "  removing a sprite";
1112           //qCDebug(KSIRK_LOG) << "i attack" << i;
1113           qCDebug(KSIRK_LOG) << "NKA" << NKA;
1114 
1115           sprite->setAnimated(1);
1116 
1117           QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
1118           if (sndCrashPath.isNull())
1119           {
1120             KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
1121             exit(2);
1122           }
1123           if (KsirkSettings::soundEnabled())
1124           {
1125             m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
1126             m_audioPlayer->play();
1127           }
1128         }
1129       }
1130       else
1131       {
1132         qCDebug(KSIRK_LOG) << "  keeping a sprite";
1133         if (sprite->isAttacker())
1134         {
1135           sprite-> changeSequence("infantry");
1136 
1137           nbAttackerSurvivor--;
1138         }
1139         sprite->setStatic();
1140         m_animFighters->oneArrived(nullptr);
1141       }
1142     }
1143   }
1144 
1145   qCDebug(KSIRK_LOG) << "  loop done attack";
1146 
1147   for (int nbSpriteTreated=0;
1148       (nbSpriteTreated < nbSpriteDefending)&&(it!=m_animFighters->end());
1149       it++,nbSpriteTreated++)
1150   {
1151     qCDebug(KSIRK_LOG) << "nbSpriteTreated" << nbSpriteTreated;
1152 
1153     AnimSprite* sprite = (AnimSprite*)(*it);
1154 
1155     if(dynamic_cast<CannonSprite*>(sprite) != nullptr)
1156     {
1157       qCDebug(KSIRK_LOG) << "*******CANNON*******";
1158 
1159       if (NKD>0)
1160       {
1161         sprite-> changeSequence("exploding");
1162 
1163         if (sprite->isDefendant())
1164         {
1165           qCDebug(KSIRK_LOG) << "  removing a sprite";
1166           //qCDebug(KSIRK_LOG) << "i attack" << i;
1167           qCDebug(KSIRK_LOG) << "NKD" << NKD;
1168 
1169           sprite->setAnimated(NKD);
1170 
1171           QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
1172           if (sndCrashPath.isNull())
1173           {
1174             KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
1175             exit(2);
1176           }
1177           if (KsirkSettings::soundEnabled())
1178           {
1179             m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
1180             m_audioPlayer->play();
1181           }
1182         }
1183       }
1184       else
1185       {
1186         sprite-> changeSequence("cannon");
1187 
1188         sprite->setStatic();
1189         m_animFighters->oneArrived(nullptr);
1190       }
1191     }
1192     else if(dynamic_cast<CavalrySprite*>(sprite) != nullptr)
1193     {
1194       qCDebug(KSIRK_LOG) << "*******CAVALIER*******";
1195 
1196       if (NKD>0)
1197       {
1198         sprite-> changeSequence("exploding");
1199 
1200         if (sprite->isDefendant())
1201         {
1202           qCDebug(KSIRK_LOG) << "  removing a sprite";
1203           //qCDebug(KSIRK_LOG) << "i attack" << i;
1204           qCDebug(KSIRK_LOG) << "NKD" << NKD;
1205 
1206           sprite->setAnimated(NKD);
1207 
1208           QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
1209           if (sndCrashPath.isNull())
1210           {
1211             KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
1212             exit(2);
1213           }
1214           if (KsirkSettings::soundEnabled())
1215           {
1216             m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
1217             m_audioPlayer->play();
1218           }
1219         }
1220       }
1221       else
1222       {
1223         sprite-> changeSequence("cavalry");
1224 
1225         sprite->setStatic();
1226         m_animFighters->oneArrived(nullptr);
1227       }
1228     }
1229     else
1230     {
1231       if (nbDefenderSurvivor<=0)
1232       {
1233         sprite-> changeSequence("exploding");
1234 
1235         if (sprite->isDefendant())
1236         {
1237           qCDebug(KSIRK_LOG) << "  removing a sprite";
1238           qCDebug(KSIRK_LOG) << "NKD" << NKD;
1239 
1240           sprite->setAnimated(1);
1241 
1242           QString sndCrashPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/crash.wav");
1243           if (sndCrashPath.isNull())
1244           {
1245             KMessageBox::information(this, i18n("Sound crash not found - Verify your installation\nProgram cannot continue"), i18n("KsirK - Error!"));
1246             exit(2);
1247           }
1248           if (KsirkSettings::soundEnabled())
1249           {
1250             m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndCrashPath));
1251             m_audioPlayer->play();
1252           }
1253         }
1254       }
1255       else  // the sprite is not the one (or one the several) killed
1256       {
1257         qCDebug(KSIRK_LOG) << "  keeping a sprite";
1258 
1259         if (sprite->isDefendant())
1260         {
1261           sprite-> changeSequence("infantry");
1262 
1263           nbDefenderSurvivor--;
1264         }
1265         sprite->setStatic();
1266         m_animFighters->oneArrived(nullptr);
1267       }
1268     }
1269   }
1270 
1271   qCDebug(KSIRK_LOG) << "  loop done defense";
1272 
1273   qCDebug(KSIRK_LOG) << "finished";
1274 }
1275 
1276 void KGameWindow::stopExplosion()
1277 {
1278     qCDebug(KSIRK_LOG);
1279     m_animFighters->hideAndRemoveAll();
1280 }
1281 
1282 void KGameWindow::initCombatBringBackForArena(Country *attackingCountry, Country *defendingCountry)
1283 {
1284   qCDebug(KSIRK_LOG);
1285   int who = 0;
1286   if ((NKD != 0)&&(NKA != 0)) who = 2;
1287   else if (NKA != 0) who = 0;
1288   else if (NKD != 0) who = 1;
1289   else KMessageBox::information(nullptr, i18n("Problem: no one destroyed"));
1290 
1291   //CannonSprite *newSprite;
1292   AnimSprite* newSprite;
1293 
1294   qreal leftRelativePos;
1295   qreal pointDepartAttaquantY;
1296   qreal pointDepartDefenseurY;
1297 
1298   qreal flagYDiff = (Sprites::SkinSpritesData::single().intData("flag-height") - Sprites::SkinSpritesData::single().intData("cannon-height"))*m_theWorld->zoom();
1299   qreal pointFlagX = backGnd()->boundingRect().width()/2;
1300 
1301   if ((attackingCountry->nbArmies() % 10) == 0)
1302   {
1303       pointDepartAttaquantY = attackingCountry-> pointCannon().y()*      m_theWorld->zoom();
1304   }
1305   else
1306   {
1307     if ((attackingCountry->nbArmies() % 5) == 0)
1308     {
1309         pointDepartAttaquantY = attackingCountry-> pointCavalry().y()*      m_theWorld->zoom();
1310     }
1311     else
1312     {
1313         pointDepartAttaquantY = attackingCountry-> pointInfantry().y()*      m_theWorld->zoom();
1314     }
1315   }
1316 
1317   if ((defendingCountry->nbArmies() % 10) == 0)
1318   {
1319       pointDepartDefenseurY = defendingCountry-> pointCannon().y()*      m_theWorld->zoom();
1320   }
1321   else
1322   {
1323     if ((defendingCountry->nbArmies() % 5) == 0)
1324     {
1325         pointDepartDefenseurY = defendingCountry-> pointCavalry().y()*      m_theWorld->zoom();
1326     }
1327     else
1328     {
1329         pointDepartDefenseurY = defendingCountry-> pointInfantry().y()*      m_theWorld->zoom();
1330     }
1331   }
1332 
1333   qreal pointArriveeY = (pointDepartAttaquantY+pointDepartDefenseurY)/2;
1334 
1335   QPointF start(pointFlagX,pointArriveeY);
1336 
1337   qreal rightRelativePos = (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("flag-width"))*m_theWorld->zoom();
1338 
1339   if (who == 0) //Attaquant detruit, ramene defenseur
1340   {
1341     if ((defendingCountry->nbArmies() % 10) == 0)
1342     {
1343       newSprite = new CannonSprite(m_theWorld->zoom(), backGnd(), 200);
1344 
1345       leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("cannon-width"))*m_theWorld->zoom();
1346     }
1347     else
1348     {
1349       if ((defendingCountry->nbArmies() % 5) == 0)
1350       {
1351         newSprite = new CavalrySprite(m_theWorld->zoom(), backGnd(), 200);
1352 
1353         leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("cavalry-width"))*m_theWorld->zoom();
1354       }
1355       else
1356       {
1357         newSprite = new InfantrySprite(m_theWorld->zoom(), backGnd(), 200);
1358 
1359         leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("infantry-width"))*m_theWorld->zoom();
1360       }
1361     }
1362 
1363     if (backGnd()->bgIsArena() || ((attackingCountry-> pointFlag().x() <= defendingCountry-> pointFlag().x()) && !((qAbs(attackingCountry-> pointFlag().x()-defendingCountry-> pointFlag().x()) > (backGnd()-> boundingRect().width() / 2)) && (attackingCountry->communicateWith(defendingCountry)))))
1364     {
1365         newSprite-> setPos((start)+QPointF(rightRelativePos, flagYDiff));
1366     }
1367     else
1368     {
1369         newSprite-> setPos((start)+QPointF(leftRelativePos, flagYDiff));
1370     }
1371 
1372     connect(newSprite,&AnimSprite::atDestination,this,&KGameWindow::slotBring);
1373 
1374     QPointF dest;
1375     //int nbPos;
1376     if ((defendingCountry->nbArmies() % 10) == 0)
1377     {
1378       //nbPos = (defendingCountry->nbArmies() / 10);
1379       //dest = QPointF(defendingCountry-> pointCannon().x()*m_theWorld->zoom(),(defendingCountry-> pointCannon().y()+(1-2*(nbPos%2))*(Sprites::SkinSpritesData::single().intData("cannon-height")+8)*((nbPos+1)/2))*m_theWorld->zoom());
1380       dest = QPointF(defendingCountry-> pointCannon().x()*m_theWorld->zoom(),(defendingCountry-> pointCannon().y()+(1-2*(0%2))*(Sprites::SkinSpritesData::single().intData("cannon-height")+8)*((0+1)/2))*m_theWorld->zoom());
1381     }
1382     else
1383     {
1384       if ((defendingCountry->nbArmies() % 5) == 0)
1385       {
1386         //nbPos = (defendingCountry->nbArmies() / 5);
1387         //dest = QPointF(defendingCountry-> pointCavalry().x()*m_theWorld->zoom(),(defendingCountry-> pointCavalry().y()+(1-2*(nbPos%2))*(Sprites::SkinSpritesData::single().intData("cavalry-height")+8)*((nbPos+1)/2))*m_theWorld->zoom());
1388         dest = QPointF(defendingCountry-> pointCavalry().x()*m_theWorld->zoom(),(defendingCountry-> pointCavalry().y()+(1-2*(0%2))*(Sprites::SkinSpritesData::single().intData("cavalry-height")+8)*((0+1)/2))*m_theWorld->zoom());
1389       }
1390       else
1391       {
1392         //nbPos = (defendingCountry->nbArmies()) % 5;
1393 
1394         //dest = QPointF(defendingCountry-> pointInfantry().x()*m_theWorld->zoom(),(defendingCountry-> pointInfantry().y()+(1-2*(nbPos%2))*(Sprites::SkinSpritesData::single().intData("infantry-height")+8)*((nbPos+1)/2))*m_theWorld->zoom());
1395         dest = QPointF(defendingCountry-> pointInfantry().x()*m_theWorld->zoom(),(defendingCountry-> pointInfantry().y()+(1-2*(0%2))*(Sprites::SkinSpritesData::single().intData("infantry-height")+8)*((0+1)/2))*m_theWorld->zoom());
1396       }
1397     }
1398 
1399     ((AnimSprite*)newSprite)-> setupTravel(attackingCountry, defendingCountry, newSprite-> pos(), dest);
1400 
1401     newSprite-> turnTowardDestination();
1402     qCDebug(KSIRK_LOG) << "add a sprite 4";
1403     m_animFighters->addSprite(newSprite);
1404 
1405     QString sndRoulePath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/roll.wav");
1406     if (sndRoulePath.isNull())
1407     {
1408         KMessageBox::error(nullptr, i18n("Sound roule not found - Verify your installation<br>Program cannot continue"), i18n("Error!"));
1409         exit(2);
1410     }
1411     if (KsirkSettings::soundEnabled())
1412     {
1413             m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndRoulePath));
1414             m_audioPlayer->play();
1415     }
1416   }
1417   else if (who == 1) //Defenseur detruit, ramene Attaquant
1418   {
1419     if ((attackingCountry->nbArmies() % 10) == 0)
1420     {
1421       newSprite = new CannonSprite(m_theWorld->zoom(), backGnd(), 200);
1422 
1423       leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("cannon-width"))*m_theWorld->zoom();
1424     }
1425     else
1426     {
1427       if ((attackingCountry->nbArmies() % 5) == 0)
1428       {
1429         newSprite = new CavalrySprite(m_theWorld->zoom(), backGnd(), 200);
1430 
1431         leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("cavalry-width"))*m_theWorld->zoom();
1432       }
1433       else
1434       {
1435         newSprite = new InfantrySprite(m_theWorld->zoom(), backGnd(), 200);
1436 
1437         leftRelativePos = - (Sprites::SkinSpritesData::single().intData("width-between-flag-and-fighter") + Sprites::SkinSpritesData::single().intData("infantry-width"))*m_theWorld->zoom();
1438       }
1439     }
1440 
1441       if (backGnd()->bgIsArena() || ((attackingCountry-> pointFlag().x() <= defendingCountry-> pointFlag().x()) && !((qAbs(attackingCountry-> pointFlag().x()-defendingCountry-> pointFlag().x()) > (backGnd()-> boundingRect().width() / 2)) && (attackingCountry->communicateWith(defendingCountry)))))
1442       {
1443           newSprite-> setPos((start)+QPointF(leftRelativePos,flagYDiff));
1444       }
1445       else
1446       {
1447           newSprite-> setPos((start)+QPointF(rightRelativePos,flagYDiff));
1448       }
1449 
1450       connect(newSprite,&AnimSprite::atDestination,this,&KGameWindow::slotBring);
1451 
1452     QPointF dest;
1453     //int nbPos;
1454     if ((attackingCountry->nbArmies() % 10) == 0)
1455     {
1456       //nbPos = (attackingCountry->nbArmies() / 10);
1457       //dest = QPointF(attackingCountry-> pointCannon().x()*m_theWorld->zoom(),(attackingCountry-> pointCannon().y()+(1-2*(nbPos%2))*(Sprites::SkinSpritesData::single().intData("cannon-height")+8)*((nbPos+1)/2))*m_theWorld->zoom());
1458       dest = QPointF(attackingCountry-> pointCannon().x()*m_theWorld->zoom(),(attackingCountry-> pointCannon().y()+(1-2*(0%2))*(Sprites::SkinSpritesData::single().intData("cannon-height")+8)*((0+1)/2))*m_theWorld->zoom());
1459     }
1460     else
1461     {
1462       if ((attackingCountry->nbArmies() % 5) == 0)
1463       {
1464         //nbPos = (attackingCountry->nbArmies() / 5);
1465         //dest = QPointF(attackingCountry-> pointCavalry().x()*m_theWorld->zoom(),(attackingCountry-> pointCavalry().y()+(1-2*(nbPos%2))*(Sprites::SkinSpritesData::single().intData("cavalry-height")+8)*((nbPos+1)/2))*m_theWorld->zoom());
1466         dest = QPointF(attackingCountry-> pointCavalry().x()*m_theWorld->zoom(),(attackingCountry-> pointCavalry().y()+(1-2*(0%2))*(Sprites::SkinSpritesData::single().intData("cavalry-height")+8)*((0+1)/2))*m_theWorld->zoom());
1467       }
1468       else
1469       {
1470         //nbPos = attackingCountry->nbArmies() % 5;
1471         //dest = QPointF(attackingCountry-> pointInfantry().x()*m_theWorld->zoom(),(attackingCountry-> pointInfantry().y()+(1-2*(nbPos%2))*(Sprites::SkinSpritesData::single().intData("infantry-height")+8)*((nbPos+1)/2))*m_theWorld->zoom());
1472         dest = QPointF(attackingCountry-> pointInfantry().x()*m_theWorld->zoom(),(attackingCountry-> pointInfantry().y()+(1-2*(0%2))*(Sprites::SkinSpritesData::single().intData("infantry-height")+8)*((0+1)/2))*m_theWorld->zoom());
1473       }
1474     }
1475 
1476       ((AnimSprite*)newSprite)-> setupTravel(defendingCountry, attackingCountry, newSprite-> pos(), dest);
1477 
1478       newSprite-> turnTowardDestination();
1479       qCDebug(KSIRK_LOG) << "add a sprite 5";
1480       m_animFighters->addSprite(newSprite);
1481 
1482       QString sndRoulePath = QStandardPaths::locate(QStandardPaths::AppDataLocation, m_automaton->skin() + "/Sounds/roll.wav");
1483       if (sndRoulePath.isNull())
1484       {
1485           KMessageBox::error(nullptr, i18n("Sound roule not found - Verify your installation<br>Program cannot continue"), i18n("Error!"));
1486           exit(2);
1487       }
1488       if (KsirkSettings::soundEnabled())
1489       {
1490               m_audioPlayer->setCurrentSource(QUrl::fromLocalFile(sndRoulePath));
1491               m_audioPlayer->play();
1492       }
1493   }
1494   else if (who == 2)
1495   {
1496   } //Attaquant ET Defenseur detruits
1497   else  // error
1498   {
1499     qCCritical(KSIRK_LOG) << Q_FUNC_INFO << __FILE__ << __LINE__ << i18n("Bug: who should be 0, 1 or 2.");
1500     exit(1);
1501   }
1502 
1503   relativePosInArenaDefense=0;
1504   relativePosInArenaAttack=0;
1505 }
1506 
1507 /**
1508   * Disconnects the mouse events signals from their slots to avoid human
1509   * player actions when it is the turn of the AI
1510   */
1511 void KGameWindow::disconnectMouse()
1512 {
1513 /*  if ( ! disconnect(m_frame, SIGNAL(signalLeftButtonDown(QPoint)),
1514                     this, SLOT(slotLeftButtonDown(QPoint))))
1515     qCCritical(KSIRK_LOG) << "cannot connect slotLeftButtonDown !";
1516   if ( ! disconnect(m_frame, SIGNAL(signalLeftButtonUp(QPoint)),
1517                     this, SLOT(slotLeftButtonUp(QPoint))))
1518     qCCritical(KSIRK_LOG) << "cannot connect slotLeftButtonUp !";
1519   if ( ! disconnect(m_frame, SIGNAL(signalRightButtonDown(QPoint)),
1520                     this, SLOT(slotRightButtonDown(QPoint))))
1521     qCCritical(KSIRK_LOG) << "cannot connect slotRightButtonDown !";*/
1522 }
1523 
1524 /**
1525   * Reconnect the mouse events signals to their slots to allow human players to
1526   * play
1527   */
1528 void KGameWindow::reconnectMouse()
1529 {
1530 /*  if ( ! connect(m_frame, SIGNAL(signalLeftButtonDown(QPoint)),
1531                     this, SLOT(slotLeftButtonDown(QPoint))))
1532   qCCritical(KSIRK_LOG) << "cannot connect slotLeftButtonDown !";
1533   if ( ! connect(m_frame, SIGNAL(signalLeftButtonUp(QPoint)),
1534                     this, SLOT(slotLeftButtonUp(QPoint))))
1535   qCCritical(KSIRK_LOG) << "cannot connect slotLeftButtonUp !";
1536   if ( ! connect(m_frame, SIGNAL(signalRightButtonDown(QPoint)),
1537                     this, SLOT(slotRightButtonDown(QPoint))))
1538   qCCritical(KSIRK_LOG) << "cannot connect slotRightButtonDown !";*/
1539 }
1540 
1541 bool KGameWindow::haveAnimFighters() const
1542 {
1543     return !m_animFighters->empty();
1544 }
1545 
1546 void KGameWindow::updateScrollArrows()
1547 {
1548   qCDebug(KSIRK_LOG);
1549   if (m_uparrow != nullptr)
1550   {
1551     QPointF pos = m_frame->mapToScene(QPoint(m_frame->viewport()->width()/2,0));
1552     pos = pos + QPointF(-(m_uparrow->boundingRect().width()/2),m_uparrow->boundingRect().height());
1553     m_uparrow->setPos(pos);
1554     m_uparrow->setActive(false);
1555   }
1556   if (m_downarrow != nullptr)
1557   {
1558     QPointF pos = m_frame->mapToScene(QPoint(m_frame->viewport()->width()/2,m_frame->viewport()->height()));
1559     pos = pos - QPointF(m_downarrow->boundingRect().width()/2,m_downarrow->boundingRect().height());
1560     m_downarrow->setPos(pos);
1561     m_downarrow->setActive(false);
1562   }
1563   if (m_leftarrow != nullptr)
1564   {
1565     QPointF pos = m_frame->mapToScene(QPoint(0,m_frame->viewport()->height()/2));
1566     pos = pos - QPointF(m_downarrow->boundingRect().width()/2,m_downarrow->boundingRect().height());
1567     pos = pos + QPointF(m_leftarrow->boundingRect().width(),-(m_leftarrow->boundingRect().height()/2));
1568     m_leftarrow->setPos(pos);
1569     m_leftarrow->setActive(false);
1570   }
1571   if (m_rightarrow != nullptr)
1572   {
1573     QPointF pos = m_frame->mapToScene(QPoint(m_frame->viewport()->width(),m_frame->viewport()->height()/2));
1574     pos = pos - QPointF(m_rightarrow->boundingRect().width(),m_rightarrow->boundingRect().height()/2);
1575     m_rightarrow->hide();
1576     m_rightarrow->setPos(pos);
1577     m_rightarrow->show();
1578     m_rightarrow->setActive(false);
1579   }
1580 }
1581 
1582 } // closing namespace KsirK