// This file is part of c-evo-evo. // // This software is governed by the CeCILL license under French law and // abiding by the rules of distribution of free software. You can use, // modify and/or redistribute the software under the terms of the CeCILL // license as circulated by CEA, CNRS and INRIA at the following URL // "http://www.cecill.info". // // As a counterpart to the access to the source code and rights to copy, // modify and redistribute granted by the license, users are provided only // with a limited warranty and the software's author, the holder of the // economic rights, and the successive licensors have only limited // liability. // // In this respect, the user's attention is drawn to the risks associated // with loading, using, modifying and/or developing or reproducing the // software by the user in light of its specific status of free software, // that may mean that it is complicated to manipulate, and that also // therefore means that it is reserved for developers and experienced // professionals having in-depth computer knowledge. Users are therefore // encouraged to load and test the software's suitability as regards their // requirements in conditions enabling the security of their systems and/or // data to be ensured and, more generally, to use and operate it in the // same conditions as regards security. // // The fact that you are presently reading this means that you have had // knowledge of the CeCILL license and that you accept its terms. #include "Diplomacy.h" #include "Global.h" #include "Tribes.h" namespace Cevo { namespace Diplomacy { namespace { QString phraseTreaty(int treatyType) { switch (treatyType) { case trCeaseFire: return QStringLiteral("a cease-fire"); case trPeace: return QStringLiteral("a peace treaty"); case trFriendlyContact: return QStringLiteral("friendly relations"); case trAlliance: return QStringLiteral("an alliance"); default: return QStringLiteral("a treaty"); } } QString phraseAdvance(int advance) { return phrases.lookup(QStringLiteral("ADVANCES"), advance); } QString priceToString(int p, std::uint32_t price) { Tribes::Tribe &tribe = *Tribes::tribe[static_cast(p)]; switch (price & static_cast(opMask)) { case opChoose: return phrases.lookup(QStringLiteral("PRICE_CHOOSE")); case opCivilReport: return tribe.tPhrase(QStringLiteral("PRICE_CIVIL")); case opMilReport: return tribe.tPhrase(QStringLiteral("PRICE_MIL")); case opMap: return tribe.tPhrase(QStringLiteral("PRICE_MAP")); case opTreaty: return phraseTreaty(static_cast(price - opTreaty)); case opShipParts: switch ((price >> 16) & 0xFu) { case 0: return formatPhrase(QStringLiteral("PRICE_SHIPCOMP"), { QString::number(price & 0xFFFFu) }); case 1: return formatPhrase(QStringLiteral("PRICE_SHIPPOW"), { QString::number(price & 0xFFFFu) }); case 2: return formatPhrase(QStringLiteral("PRICE_SHIPHAB"), { QString::number(price & 0xFFFFu) }); default: return QString(); } case opMoney: return QStringLiteral("%1%c").arg(price - opMoney); case opTribute: return formatPhrase(QStringLiteral("PRICE_TRIBUTE"), { QString::number(price - opTribute) }); case opTech: return phraseAdvance(static_cast(price - opTech)); case opAllTech: return tribe.tPhrase(QStringLiteral("PRICE_ALLTECH")); case opModel: return tribe.modelNameAt(static_cast(price - opModel)); case opAllModel: return tribe.tPhrase(QStringLiteral("PRICE_ALLMODEL")); default: return QString(); } } } // namespace QString dipCommandToString(int pSender, int pTarget, int treaty, int oppCommand, int command, const TOffer &oppOffer, const TOffer &offer) { Tribes::Tribe &sender = *Tribes::tribe[static_cast(pSender)]; Tribes::Tribe &target = *Tribes::tribe[static_cast(pTarget)]; bool doIntro = oppCommand == scDipStart; QString result; switch (command) { case scDipCancelTreaty: switch (treaty) { case trPeace: result = phrases.lookup(QStringLiteral("FRCANCELTREATY_PEACE")); break; case trFriendlyContact: result = phrases.lookup(QStringLiteral("FRCANCELTREATY_FRIENDLY")); break; case trAlliance: result = phrases.lookup(QStringLiteral("FRCANCELTREATY_ALLIANCE")); break; default: break; } doIntro = false; break; case scDipNotice: result = phrases.lookup(QStringLiteral("FRNOTICE")); break; case scDipAccept: if (oppOffer.nDeliver + oppOffer.nCost == 1 && (oppOffer.Price[0] & static_cast(opMask)) == opTreaty && static_cast(oppOffer.Price[0] - opTreaty) > treaty) result = target.tPhrase(QStringLiteral("FRACCEPTTREATY")); else if (oppOffer.nDeliver == 0) result = sender.tPhrase(QStringLiteral("FRACCEPTDEMAND_STRONG")); else if (oppOffer.nCost == 0) result = sender.tPhrase(QStringLiteral("FRACCEPTPRESENT")); else result = sender.tPhrase(QStringLiteral("FRACCEPTOFFER")); break; case scDipBreak: result = target.tPhrase(QStringLiteral("FRBREAK")); doIntro = false; break; case scDipOffer: { if (oppCommand == scDipOffer && (oppOffer.nDeliver > 0 || oppOffer.nCost > 0) && offer.nCost + offer.nDeliver <= 2) { // Respond to the offer the other side just made before making our own. if (oppOffer.nDeliver + oppOffer.nCost == 1 && (oppOffer.Price[0] & static_cast(opMask)) == opTreaty && static_cast(oppOffer.Price[0] - opTreaty) > treaty) result = sender.tPhrase(QStringLiteral("FRNOTACCEPTTREATY")) + QLatin1Char('\\'); else if (oppOffer.nDeliver == 0) result = sender.tPhrase(QStringLiteral("FRNOTACCEPTDEMAND_STRONG")) + QLatin1Char('\\'); else if (oppOffer.nCost == 0) result = sender.tPhrase(QStringLiteral("FRNOTACCEPTPRESENT")) + QLatin1Char('\\'); } QString sDeliver; for (int i = 0; i < offer.nDeliver; ++i) { const QString sAdd = priceToString(pSender, offer.Price[i]); sDeliver = i == 0 ? sAdd : formatPhrase(QStringLiteral("PRICE_CONCAT"), { sDeliver, sAdd }); } QString sCost; for (int i = 0; i < offer.nCost; ++i) { const QString sAdd = priceToString(pTarget, offer.Price[offer.nDeliver + i]); sCost = i == 0 ? sAdd : formatPhrase(QStringLiteral("PRICE_CONCAT"), { sCost, sAdd }); } if (offer.nDeliver == 0 && offer.nCost == 0) { if (oppCommand == scDipOffer && oppOffer.nDeliver == 0 && oppOffer.nCost == 0) { result = target.tPhrase(QStringLiteral("FRBYE")); } else { if (result.isEmpty() && oppCommand == scDipOffer && (oppOffer.nDeliver > 0 || oppOffer.nCost > 0)) { // The original also has two Phrases2-based "soft" variants // here, unreachable without a StringTables.pas port. result = sender.tPhrase(QStringLiteral("FRNOTACCEPTOFFER")) + QLatin1Char(' '); } result += phrases.lookup(QStringLiteral("FRDONE")); doIntro = false; } } else if (offer.nDeliver + offer.nCost == 1 && (offer.Price[0] & static_cast(opMask)) == opTreaty && static_cast(offer.Price[0] - opTreaty) > treaty) { switch (offer.Price[0] - opTreaty) { case trPeace: result += target.tPhrase(QStringLiteral("FRPEACE")); break; case trFriendlyContact: result += target.tPhrase(QStringLiteral("FRFRIENDLY")); break; case trAlliance: result += target.tPhrase(QStringLiteral("FRALLIANCE")); break; default: break; } } else if (offer.nDeliver == 0) { // The original also has a Phrases2-based "soft" demand variant // here, unreachable without a StringTables.pas port. result += target.tPhrase(QStringLiteral("FRDEMAND_STRONG")).arg(sCost); doIntro = false; } else if (offer.nCost == 0) { result += target.tPhrase(QStringLiteral("FRPRESENT")).arg(sDeliver); } else if (offer.nDeliver == 1 && offer.Price[0] == opChoose) { result += formatPhrase(QStringLiteral("FRDELCHOICE"), { sCost }); } else if (offer.nCost == 1 && offer.Price[offer.nDeliver] == opChoose) { result += formatPhrase(QStringLiteral("FRCOSTCHOICE"), { sDeliver }); } else { result += formatPhrase(QStringLiteral("FROFFER"), { sDeliver, sCost }); } break; } default: break; } if (doIntro) { if (treaty < trPeace) result = sender.tPhrase(QStringLiteral("FRSTART_NOTREATY")) + QLatin1Char(' ') + result; else result = sender.tPhrase(QStringLiteral("FRSTART_PEACE")) + QLatin1Char(' ') + result; } return result; } } // namespace Diplomacy } // namespace Cevo