added nego with deps

This commit is contained in:
Geoffray Levasseur committed 2026-11-03 17:24:50 +01:00
1 parent d65065644e
commit 1da33b4cf7
6 files changed
+1208 -2

No files matched your search

+3
View File
@@ -163,6 +163,9 @@ set(PROJECT_SOURCES
game/localplayer/Select.cpp
game/localplayer/Select.h
game/localplayer/Select.ui
game/localplayer/Nego.cpp
game/localplayer/Nego.h
game/localplayer/Nego.ui
${TS_FILES}
)
+909
View File
@@ -0,0 +1,909 @@
// 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 "Nego.h"
#include "ui_Nego.h"
#include "Cevo/CevoButtonN.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
#include "ClientTools.h"
#include "Diplomacy.h"
#include "Inp.h"
#include "IsoEngine.h"
#include "MessgEx.h"
#include "Select.h"
#include "Term.h"
#include "Tribes.h"
#include <QCloseEvent>
#include <QKeyEvent>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPainter>
namespace Cevo {
namespace Nego {
namespace {
constexpr int xPadC = 140;
constexpr int yPadC = 427;
constexpr int xPad0 = 140;
constexpr int yPad0 = 13;
constexpr int xPad1 = 334;
constexpr int yPad1 = 13;
constexpr int wText = 300;
constexpr int hText = 256;
constexpr int xText0 = 14;
constexpr int yText0 = 154;
constexpr int xText1 = 326;
constexpr int yText1 = 154;
constexpr int xNationPicture0 = 20;
constexpr int xNationPicture1 = 556;
constexpr int yNationPicture = 40;
constexpr int xCred0 = 42;
constexpr int yCred0 = 92;
constexpr int xCred1 = 578;
constexpr int yCred1 = 92;
constexpr int PaperShade = 3;
constexpr int PaperBorder_Left = 12;
constexpr int PaperBorder_Right = 8;
constexpr int ListIndent = 24;
const std::array<QString, 16> RomanNo = {
QStringLiteral("I"), QStringLiteral("II"), QStringLiteral("III"), QStringLiteral("IV"),
QStringLiteral("V"), QStringLiteral("VI"), QStringLiteral("VII"), QStringLiteral("VIII"),
QStringLiteral("IX"), QStringLiteral("X"), QStringLiteral("XI"), QStringLiteral("XII"),
QStringLiteral("XIII"), QStringLiteral("XIV"), QStringLiteral("XV"), QStringLiteral("XVI"),
};
const std::array<std::uint32_t, 12> ButtonPrice = {
static_cast<std::uint32_t>(opChoose), static_cast<std::uint32_t>(opCivilReport),
static_cast<std::uint32_t>(opMilReport), static_cast<std::uint32_t>(opMap),
static_cast<std::uint32_t>(opAllTech), static_cast<std::uint32_t>(opAllTech),
static_cast<std::uint32_t>(opAllModel), static_cast<std::uint32_t>(opMoney),
static_cast<std::uint32_t>(opTreaty), 0xFE000000u, // opLowTreaty (not used by any live case below)
static_cast<std::uint32_t>(opShipParts), static_cast<std::uint32_t>(opShipParts),
};
// Phrases/Phrases2 (StringTables.pas) aren't ported; disclosed
// plain-English placeholders for this dialog's own text.
QString phrase(const QString &key)
{
static const QHash<QString, QString> table = {
{QStringLiteral("BTN_OK"), QStringLiteral("OK")},
{QStringLiteral("BTN_ACCEPT"), QStringLiteral("Accept")},
{QStringLiteral("BTN_BREAK"), QStringLiteral("Break off")},
{QStringLiteral("BTN_CNTREATY"), QStringLiteral("Cancel treaty")},
{QStringLiteral("BTN_NOTICE"), QStringLiteral("Notice")},
{QStringLiteral("BTN_PASS"), QStringLiteral("Pass")},
{QStringLiteral("BTN_WANTPEACE"), QStringLiteral("Want peace")},
{QStringLiteral("BTN_OFFERPEACE"), QStringLiteral("Offer peace")},
{QStringLiteral("BTN_WANTFRIENDLY"), QStringLiteral("Want friendly relations")},
{QStringLiteral("BTN_OFFERFRIENDLY"), QStringLiteral("Offer friendly relations")},
{QStringLiteral("BTN_WANTALLIANCE"), QStringLiteral("Want alliance")},
{QStringLiteral("BTN_OFFERALLIANCE"), QStringLiteral("Offer alliance")},
{QStringLiteral("MAX2WANTS"), QStringLiteral("You can only ask for 2 things at once.")},
{QStringLiteral("MAX2OFFERS"), QStringLiteral("You can only offer 2 things at once.")},
{QStringLiteral("CANCELTREATYRUSH"), QStringLiteral("You can't cancel the treaty again so soon.")},
{QStringLiteral("TITLE_AMOUNT"), QStringLiteral("Enter amount")},
{QStringLiteral("TITLE_NUMBER"), QStringLiteral("Enter number")},
{QStringLiteral("NOSPACEPORT"), QStringLiteral("We have no space port to ship parts from.")},
{QStringLiteral("WANT_ANYTHING"), QStringLiteral("Anything")},
{QStringLiteral("WANT_STATEREPORT"), QStringLiteral("State report")},
{QStringLiteral("WANT_MILREPORT"), QStringLiteral("Military report")},
{QStringLiteral("WANT_MAP"), QStringLiteral("Map")},
{QStringLiteral("WANT_TECH"), QStringLiteral("Advance")},
{QStringLiteral("WANT_MODEL"), QStringLiteral("Unit design")},
{QStringLiteral("WANT_MONEY"), QStringLiteral("Money")},
{QStringLiteral("WANT_HITREATY"), QStringLiteral("Improve treaty")},
{QStringLiteral("WANT_LOTREATY"), QStringLiteral("Worsen treaty")},
{QStringLiteral("WANT_SHIPPART"), QStringLiteral("Ship part")},
{QStringLiteral("OFFER_ANYTHING"), QStringLiteral("Anything")},
{QStringLiteral("OFFER_STATEREPORT"), QStringLiteral("State report")},
{QStringLiteral("OFFER_MILREPORT"), QStringLiteral("Military report")},
{QStringLiteral("OFFER_MAP"), QStringLiteral("Map")},
{QStringLiteral("OFFER_TECH"), QStringLiteral("Advance")},
{QStringLiteral("OFFER_MODEL"), QStringLiteral("Unit design")},
{QStringLiteral("OFFER_MONEY"), QStringLiteral("Money")},
{QStringLiteral("OFFER_HITREATY"), QStringLiteral("Improve treaty")},
{QStringLiteral("OFFER_LOTREATY"), QStringLiteral("Worsen treaty")},
{QStringLiteral("OFFER_SHIPPART"), QStringLiteral("Ship part")},
};
const auto it = table.constFind(key);
return it != table.constEnd() ? *it : key;
}
} // namespace
NegoDlg::NegoDlg(QWidget *parent) : BufferedDrawDlg(parent), ui(new Ui::NegoDlg)
{
ui->setupUi(this);
initButtons();
wantButtons = {ui->wantAnythingBtn, ui->wantStateReportBtn, ui->wantMilReportBtn, ui->wantMapBtn,
ui->wantTech1Btn, ui->wantTech2Btn, ui->wantModelBtn, ui->wantMoneyBtn,
ui->wantHiTreatyBtn, ui->wantLoTreatyBtn, ui->wantShipPart1Btn, ui->wantShipPart2Btn};
offerButtons = {ui->offerAnythingBtn, ui->offerStateReportBtn, ui->offerMilReportBtn, ui->offerMapBtn,
ui->offerTech1Btn, ui->offerTech2Btn, ui->offerModelBtn, ui->offerMoneyBtn,
ui->offerHiTreatyBtn, ui->offerLoTreatyBtn, ui->offerShipPart1Btn, ui->offerShipPart2Btn};
const std::array<QString, 12> wantHints = {
phrase(QStringLiteral("WANT_ANYTHING")), phrase(QStringLiteral("WANT_STATEREPORT")),
phrase(QStringLiteral("WANT_MILREPORT")), phrase(QStringLiteral("WANT_MAP")),
phrase(QStringLiteral("WANT_TECH")), phrase(QStringLiteral("WANT_TECH")),
phrase(QStringLiteral("WANT_MODEL")), phrase(QStringLiteral("WANT_MONEY")),
phrase(QStringLiteral("WANT_HITREATY")), phrase(QStringLiteral("WANT_LOTREATY")),
phrase(QStringLiteral("WANT_SHIPPART")), phrase(QStringLiteral("WANT_SHIPPART")),
};
const std::array<QString, 12> offerHints = {
phrase(QStringLiteral("OFFER_ANYTHING")), phrase(QStringLiteral("OFFER_STATEREPORT")),
phrase(QStringLiteral("OFFER_MILREPORT")), phrase(QStringLiteral("OFFER_MAP")),
phrase(QStringLiteral("OFFER_TECH")), phrase(QStringLiteral("OFFER_TECH")),
phrase(QStringLiteral("OFFER_MODEL")), phrase(QStringLiteral("OFFER_MONEY")),
phrase(QStringLiteral("OFFER_HITREATY")), phrase(QStringLiteral("OFFER_LOTREATY")),
phrase(QStringLiteral("OFFER_SHIPPART")), phrase(QStringLiteral("OFFER_SHIPPART")),
};
const std::array<int, 12> buttonIndex = {17, 6, 7, 8, 10, 10, 11, 12, 14, 15, 16, 16};
for (int i = 0; i < 12; ++i) {
ButtonN *w = wantButtons[static_cast<std::size_t>(i)];
ButtonN *o = offerButtons[static_cast<std::size_t>(i)];
if (HGrSystem) {
w->setGraphic(&HGrSystem->data);
w->setMask(&HGrSystem->mask);
o->setGraphic(&HGrSystem->data);
o->setMask(&HGrSystem->mask);
}
if (HGrSystem2) {
w->setBackGraphic(&HGrSystem2->data);
o->setBackGraphic(&HGrSystem2->data);
}
w->setButtonIndex(buttonIndex[static_cast<std::size_t>(i)]);
o->setButtonIndex(buttonIndex[static_cast<std::size_t>(i)]);
w->setSmartHint(wantHints[static_cast<std::size_t>(i)]);
o->setSmartHint(offerHints[static_cast<std::size_t>(i)]);
w->onClick = [this, i] { wantClicked(i); };
o->onClick = [this, i] { offerClicked(i); };
}
ui->acceptBtn->setButtonIndex(0);
ui->passBtn->setButtonIndex(1);
ui->exitBtn->setButtonIndex(2);
ui->cancelTreatyBtn->setButtonIndex(3);
for (ButtonN *b : {ui->acceptBtn, ui->passBtn, ui->exitBtn, ui->cancelTreatyBtn}) {
if (HGrSystem) {
b->setGraphic(&HGrSystem->data);
b->setMask(&HGrSystem->mask);
}
if (HGrSystem2)
b->setBackGraphic(&HGrSystem2->data);
}
ui->acceptBtn->onClick = [this] { fastClicked(scDipAccept - scDipStart); };
ui->passBtn->onClick = [this] { fastClicked(scDipOffer - scDipStart); };
ui->exitBtn->onClick = [this] { fastClicked(scDipBreak - scDipStart); };
ui->cancelTreatyBtn->onClick = [this] { fastClicked(scDipCancelTreaty - scDipStart); };
helpContext = QStringLiteral("DIPLOMACY");
ui->okBtn->setCaption(phrase(QStringLiteral("BTN_OK")));
ui->acceptBtn->setSmartHint(phrase(QStringLiteral("BTN_ACCEPT")));
ui->exitBtn->setSmartHint(phrase(QStringLiteral("BTN_BREAK")));
ui->cancelTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_CNTREATY")));
romanFont.setName(QStringLiteral("Times New Roman"));
romanFont.setSize(20);
ui->closeBtn->onClick = [this] { close(); };
ui->bwdBtn->onClick = [this] {
page -= 2;
setButtonStates();
smartUpdateContent();
};
ui->fwdBtn->onClick = [this] {
page += 2;
setButtonStates();
smartUpdateContent();
};
ui->okBtn->onClick = [this] {
++history[static_cast<std::size_t>(ClientTools::me)].n;
if (dipCommand == scDipOffer)
Term::mainScreenOfferCall(currentOffer);
else
Term::mainScreenDipCall(dipCommand);
};
onShow = [this] { offscreenPaint(); };
}
NegoDlg::~NegoDlg()
{
delete ui;
}
void NegoDlg::resetCurrentOffer()
{
currentOffer.nDeliver = 0;
currentOffer.nCost = 0;
costs.fill(0xFFFFFFFFu);
delivers.fill(0xFFFFFFFFu);
}
void NegoDlg::buildCurrentOffer()
{
currentOffer.nDeliver = 0;
currentOffer.nCost = 0;
for (std::uint32_t d : delivers)
if (d != 0xFFFFFFFFu) {
currentOffer.Price[currentOffer.nDeliver] = d;
++currentOffer.nDeliver;
}
for (std::uint32_t c : costs)
if (c != 0xFFFFFFFFu) {
currentOffer.Price[currentOffer.nDeliver + currentOffer.nCost] = c;
++currentOffer.nCost;
}
}
void NegoDlg::showNewContent(WindowMode newMode)
{
BufferedDrawDlg::showNewContent(newMode);
setButtonStates();
const int pContact = Term::dipMem[static_cast<std::size_t>(ClientTools::me)].pContact;
ui->passBtn->setSmartHint(IsoEngine::clientMode == scDipCancelTreaty || IsoEngine::clientMode == scDipBreak
? phrase(QStringLiteral("BTN_NOTICE"))
: phrase(QStringLiteral("BTN_PASS")));
switch (ClientTools::myRO->Treaty[pContact]) {
case trNone:
ui->wantHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_WANTPEACE")));
ui->offerHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_OFFERPEACE")));
break;
case trPeace:
ui->wantHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_WANTFRIENDLY")));
ui->offerHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_OFFERFRIENDLY")));
break;
case trFriendlyContact:
ui->wantHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_WANTALLIANCE")));
ui->offerHiTreatyBtn->setSmartHint(phrase(QStringLiteral("BTN_OFFERALLIANCE")));
break;
default:
break;
}
}
void NegoDlg::start()
{
const int me = ClientTools::me;
const int pContact = Term::dipMem[static_cast<std::size_t>(me)].pContact;
if (IsoEngine::clientMode != scDipStart) {
History &h = history[static_cast<std::size_t>(me)];
if (h.n == MaxHistory) {
for (int i = 0; i < MaxHistory - 2; ++i)
h.text[static_cast<std::size_t>(i)] = h.text[static_cast<std::size_t>(i + 2)];
h.n -= 2;
}
h.text[static_cast<std::size_t>(h.n)] =
Diplomacy::dipCommandToString(pContact, me, Term::dipMem[static_cast<std::size_t>(me)].formerTreaty,
Term::dipMem[static_cast<std::size_t>(me)].sentCommand,
IsoEngine::clientMode, Term::dipMem[static_cast<std::size_t>(me)].sentOffer,
Term::receivedOffer)
.left(255);
++h.n;
}
Q_ASSERT(history[static_cast<std::size_t>(me)].n % 2 == 1);
page = history[static_cast<std::size_t>(me)].n;
findAllowed();
resetCurrentOffer();
dipCommand = -1;
showNewContent(WindowMode::Persistent);
}
void NegoDlg::initiate()
{
history[static_cast<std::size_t>(ClientTools::me)].n = 1;
history[static_cast<std::size_t>(ClientTools::me)].text[0].clear();
}
void NegoDlg::respond()
{
history[static_cast<std::size_t>(ClientTools::me)].n = 0;
}
void NegoDlg::findAllowed()
{
const int me = ClientTools::me;
const int pContact = Term::dipMem[static_cast<std::size_t>(me)].pContact;
commandAllowed.reset();
commandAllowed.set(static_cast<std::size_t>(scDipOffer - scDipStart));
if (IsoEngine::clientMode != scDipBreak)
commandAllowed.set(static_cast<std::size_t>(scDipBreak - scDipStart));
if (ClientTools::myRO->Treaty[pContact] >= trPeace)
commandAllowed.set(static_cast<std::size_t>(scDipCancelTreaty - scDipStart));
if (IsoEngine::clientMode == scDipOffer) {
int dummy = 0;
if (ClientTools::server(scDipAccept - sExecute, me, 0, &dummy) >= rExecuted)
commandAllowed.set(static_cast<std::size_t>(scDipAccept - scDipStart));
}
myAllowed.reset();
oppoAllowed.reset();
myAllowed.set(static_cast<std::size_t>(opChoose >> 24));
myAllowed.set(static_cast<std::size_t>(opMoney >> 24));
oppoAllowed.set(static_cast<std::size_t>(opChoose >> 24));
oppoAllowed.set(static_cast<std::size_t>(opMoney >> 24));
if (!ClientTools::isCivilReportNew(pContact)) {
myAllowed.set(static_cast<std::size_t>(opCivilReport >> 24));
for (int i = 0; i < nAdv; ++i)
if (ClientTools::myRO->Tech[i] >= tsApplicable) {
myAllowed.set(static_cast<std::size_t>(opAllTech >> 24));
break;
}
oppoAllowed.set(static_cast<std::size_t>(opCivilReport >> 24));
oppoAllowed.set(static_cast<std::size_t>(opAllTech >> 24));
} else {
for (int i = 0; i < nAdv; ++i)
if (!IsFutureTech(i)) {
if (ClientTools::myRO->Tech[i] < tsSeen &&
ClientTools::myRO->EnemyReport[pContact]->Tech[i] >= tsApplicable)
oppoAllowed.set(static_cast<std::size_t>(opAllTech >> 24));
else if (ClientTools::myRO->EnemyReport[pContact]->Tech[i] < tsSeen &&
ClientTools::myRO->Tech[i] >= tsApplicable)
myAllowed.set(static_cast<std::size_t>(opAllTech >> 24));
}
}
if (!ClientTools::isMilReportNew(pContact)) {
myAllowed.set(static_cast<std::size_t>(opMilReport >> 24));
if (ClientTools::myRO->nModel > 3)
myAllowed.set(static_cast<std::size_t>(opAllModel >> 24));
oppoAllowed.set(static_cast<std::size_t>(opMilReport >> 24));
oppoAllowed.set(static_cast<std::size_t>(opAllModel >> 24));
} else if (auto *dlg = Term::mainScreenModalSelectDlg()) {
if (dlg->onlyChoice(Select::ListKind::ChooseModel) != Select::mixAll)
myAllowed.set(static_cast<std::size_t>(opAllModel >> 24));
if (dlg->onlyChoice(Select::ListKind::ChooseEnemyModel) != Select::mixAll)
oppoAllowed.set(static_cast<std::size_t>(opAllModel >> 24));
}
if (ClientTools::myRO->Treaty[pContact] < trAlliance) {
myAllowed.set(static_cast<std::size_t>(opTreaty >> 24));
myAllowed.set(static_cast<std::size_t>(opMap >> 24));
oppoAllowed.set(static_cast<std::size_t>(opTreaty >> 24));
oppoAllowed.set(static_cast<std::size_t>(opMap >> 24));
}
for (int i = 0; i < nShipPart; ++i) {
if (ClientTools::myRO->Ship[me].Parts[i] > 0)
myAllowed.set(static_cast<std::size_t>(opShipParts >> 24));
if (ClientTools::myRO->Ship[pContact].Parts[i] > 0)
oppoAllowed.set(static_cast<std::size_t>(opShipParts >> 24));
}
const std::array<int, 5> reportBits = {opAllTech >> 24, opAllModel >> 24, opCivilReport >> 24,
opMilReport >> 24, opMap >> 24};
for (int bit : reportBits) {
if (Term::dipMem[static_cast<std::size_t>(me)].deliveredPrices.test(static_cast<std::size_t>(bit)))
myAllowed.reset(static_cast<std::size_t>(bit));
if (Term::dipMem[static_cast<std::size_t>(me)].receivedPrices.test(static_cast<std::size_t>(bit)))
oppoAllowed.reset(static_cast<std::size_t>(bit));
}
}
void NegoDlg::paintNationPicture(int x, int y, int p)
{
if (!HGrSystem)
return;
Dpi::Canvas &canvas = offscreen.canvas();
canvas.pen().setColor(Qt::black);
canvas.brush().setStyle(Qt::SolidPattern);
canvas.brush().setColor(Tribes::tribe[static_cast<std::size_t>(p)]->color);
canvas.rectangle(x - 6, y - 1, x + 70, y + 49);
canvas.brush().setColor(Qt::black);
Tribes::tribe[static_cast<std::size_t>(p)]->initAge(ClientTools::getAge(p));
if (Tribes::tribe[static_cast<std::size_t>(p)]->faceHGr)
dump(offscreen, *Tribes::tribe[static_cast<std::size_t>(p)]->faceHGr, x, y, 64, 48,
1 + Tribes::tribe[static_cast<std::size_t>(p)]->facePix % 10 * 65,
1 + Tribes::tribe[static_cast<std::size_t>(p)]->facePix / 10 * 49);
else
canvas.fillRect(QRect(x, y, 64, 48));
canvas.brush().setStyle(Qt::NoBrush);
frame(canvas, x - 1, y - 1, x + 64, y + 48, Qt::black, Qt::black);
}
void NegoDlg::setButtonStates()
{
const bool isActionPage = page == history[static_cast<std::size_t>(ClientTools::me)].n;
ui->acceptBtn->setPossible(isActionPage && commandAllowed.test(static_cast<std::size_t>(scDipAccept - scDipStart)));
ui->acceptBtn->setLit(dipCommand == scDipAccept);
ui->passBtn->setPossible(isActionPage && commandAllowed.test(static_cast<std::size_t>(scDipOffer - scDipStart)));
ui->passBtn->setLit(dipCommand == scDipNotice ||
(dipCommand == scDipOffer && currentOffer.nDeliver == 0 && currentOffer.nCost == 0));
ui->exitBtn->setPossible(isActionPage && commandAllowed.test(static_cast<std::size_t>(scDipBreak - scDipStart)));
ui->exitBtn->setLit(dipCommand == scDipBreak);
ui->cancelTreatyBtn->setPossible(
isActionPage && commandAllowed.test(static_cast<std::size_t>(scDipCancelTreaty - scDipStart)));
ui->cancelTreatyBtn->setLit(dipCommand == scDipCancelTreaty);
for (int i = 0; i < 12; ++i) {
const std::size_t priceBit = static_cast<std::size_t>(ButtonPrice[static_cast<std::size_t>(i)] >> 24);
offerButtons[static_cast<std::size_t>(i)]->setPossible(isActionPage && oppoAllowed.test(priceBit));
offerButtons[static_cast<std::size_t>(i)]->setLit(costs[static_cast<std::size_t>(i)] != 0xFFFFFFFFu);
wantButtons[static_cast<std::size_t>(i)]->setPossible(isActionPage && myAllowed.test(priceBit));
wantButtons[static_cast<std::size_t>(i)]->setLit(delivers[static_cast<std::size_t>(i)] != 0xFFFFFFFFu);
}
}
void NegoDlg::offscreenPaint()
{
BufferedDrawDlg::offscreenPaint();
if (!MainTexture || !HGrSystem)
return;
const int me = ClientTools::me;
const int pContact = Term::dipMem[static_cast<std::size_t>(me)].pContact;
History &myHistory = history[static_cast<std::size_t>(me)];
if (dipCommand >= 0 && page == myHistory.n)
myHistory.text[static_cast<std::size_t>(myHistory.n)] =
Diplomacy::dipCommandToString(me, pContact, ClientTools::myRO->Treaty[pContact], IsoEngine::clientMode,
dipCommand, Term::receivedOffer, currentOffer)
.left(255);
ui->fwdBtn->setVisible(page < myHistory.n);
ui->bwdBtn->setVisible(page >= 2);
bool okEnabled;
if (page < myHistory.n)
okEnabled = false;
else if (dipCommand == scDipOffer)
okEnabled = ClientTools::server(scDipOffer - sExecute, me, 0, &currentOffer) >= rExecuted;
else
okEnabled = dipCommand >= 0;
ui->okBtn->setVisible(okEnabled);
Dpi::Canvas &canvas = offscreen.canvas();
canvas.begin();
fill(canvas, 3, 3, width() - 6, height() - 6, (MainTexture->width() - width()) / 2,
(MainTexture->height() - height()) / 2);
frame(canvas, 0, 0, width() - 1, height() - 1, Qt::black, Qt::black);
frame(canvas, 1, 1, width() - 2, height() - 2, MainTexture->colorBevelLight, MainTexture->colorBevelShade);
frame(canvas, 2, 2, width() - 3, height() - 3, MainTexture->colorBevelLight, MainTexture->colorBevelShade);
corner(canvas, 1, 1, 0, *MainTexture);
corner(canvas, width() - 9, 1, 1, *MainTexture);
corner(canvas, 1, height() - 9, 2, *MainTexture);
corner(canvas, width() - 9, height() - 9, 3, *MainTexture);
btnFrame(canvas, ui->okBtn->geometry(), *MainTexture);
btnFrame(canvas, ui->bwdBtn->geometry(), *MainTexture);
btnFrame(canvas, ui->fwdBtn->geometry(), *MainTexture);
btnFrame(canvas, ui->closeBtn->geometry(), *MainTexture);
rframe(canvas, xPadC - 2, yPadC - 2, xPadC + 41 + 42 * 3, yPadC + 41, colorFromDelphi(0xFFFFFF),
colorFromDelphi(0xB0B0B0));
rframe(canvas, xPad0 - 2, yPad0 - 2, xPad0 + 41 + 42 * 3, yPad0 + 41 + 42 * 2, colorFromDelphi(0xFFFFFF),
colorFromDelphi(0xB0B0B0));
rframe(canvas, xPad1 - 2, yPad1 - 2, xPad1 + 41 + 42 * 3, yPad1 + 41 + 42 * 2, colorFromDelphi(0xFFFFFF),
colorFromDelphi(0xB0B0B0));
paintNationPicture(xNationPicture0, yNationPicture, pContact);
paintNationPicture(xNationPicture1, yNationPicture, me);
if (!myHistory.text[static_cast<std::size_t>(page - 1)].isEmpty()) {
fillSeamless(canvas, xText0, yText0, wText, hText, 0, 0, paper);
int i = page - 1;
if (myHistory.text[0].isEmpty())
--i;
if (i < 16) {
canvas.font().assign(romanFont);
canvas.textOut(xText0 + (wText - canvas.textWidth(RomanNo[static_cast<std::size_t>(i)])) / 2,
yText0 + (hText - canvas.textExtent(RomanNo[static_cast<std::size_t>(i)]).height()) / 2,
RomanNo[static_cast<std::size_t>(i)]);
}
}
fillSeamless(canvas, xText1, yText1, wText, hText, 0, 0, paper);
{
int i = page;
if (myHistory.text[0].isEmpty())
--i;
if (i < 16) {
canvas.font().assign(romanFont);
canvas.textOut(xText1 + (wText - canvas.textWidth(RomanNo[static_cast<std::size_t>(i)])) / 2,
yText1 + (hText - canvas.textExtent(RomanNo[static_cast<std::size_t>(i)]).height()) / 2,
RomanNo[static_cast<std::size_t>(i)]);
}
}
canvas.brush().setStyle(Qt::SolidPattern);
canvas.brush().setColor(MainTexture->colorBevelShade);
if (!myHistory.text[static_cast<std::size_t>(page - 1)].isEmpty()) {
canvas.fillRect(QRect(xText0 + wText, yText0 + PaperShade, PaperShade, hText + PaperShade));
canvas.fillRect(QRect(xText0 + PaperShade, yText0 + hText, wText + PaperShade - PaperShade, PaperShade));
}
canvas.fillRect(QRect(xText1 + wText, yText1 + PaperShade, PaperShade, hText + PaperShade));
canvas.fillRect(QRect(xText1 + PaperShade, yText1 + hText, wText + PaperShade - PaperShade, PaperShade));
canvas.brush().setStyle(Qt::NoBrush);
canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Normal)]);
if (!myHistory.text[static_cast<std::size_t>(page - 1)].isEmpty())
splitText(myHistory.text[static_cast<std::size_t>(page - 1)],
QRect(xText0, yText0, xText0 + wText, yText0 + hText));
if (page < myHistory.n || okEnabled)
splitText(myHistory.text[static_cast<std::size_t>(page)], QRect(xText1, yText1, xText1 + wText, yText1 + hText));
canvas.font().assign(UniFont[static_cast<std::size_t>(FontType::Tiny)]);
int cred = ClientTools::myRO->EnemyReport[pContact]->Credibility;
int kind = cred <= 49 ? 3 : (cred <= 90 ? 0 : 1);
paintProgressBar(canvas, kind, xCred0, yCred0 + 17, (cred + 2) / 5, 0, 20, *MainTexture);
QString s = QString::number(cred);
risedTextOut(canvas, xCred0 + 10 - (biColorTextWidth(canvas, s) + 1) / 2, yCred0, s);
cred = ClientTools::myRO->Credibility;
kind = cred <= 49 ? 3 : (cred <= 90 ? 0 : 1);
paintProgressBar(canvas, kind, xCred1, yCred1 + 17, (cred + 2) / 5, 0, 20, *MainTexture);
s = QString::number(cred);
risedTextOut(canvas, xCred1 + 10 - (biColorTextWidth(canvas, s) + 1) / 2, yCred1, s);
canvas.end();
markUsedOffscreen(width(), height());
}
void NegoDlg::splitText(const QString &text, const QRect &bounds)
{
if (!HGrSystem || !Colors)
return;
const QString t = QStringLiteral(" ") + text; // mirrors Pascal's 1-based string indexing
const int length = t.length() - 1;
Dpi::Canvas &canvas = offscreen.canvas();
int nLines = 0;
for (int previewPass = 1; previewPass >= 0; --previewPass) {
const bool preview = previewPass != 0;
int start = 1;
int line = 0;
int indent = 0;
while (start < length) {
bool dot = false;
if (start == 1 || t[start - 1] == QLatin1Char('\\')) {
if (t[start] == QLatin1Char('-')) {
indent = ListIndent;
++start;
if (start == length)
break;
dot = true;
} else {
indent = 0;
}
}
int stop = start;
while (stop < length && t[stop] != QLatin1Char('\\')) {
++stop;
if (biColorTextWidth(canvas, t.mid(start, stop - start + 1)) >
bounds.right() - bounds.left() - PaperBorder_Left - PaperBorder_Right - indent) {
--stop;
break;
}
}
if (stop != length) {
int ordinaryStop = stop;
while (t[ordinaryStop + 1] != QLatin1Char(' ') && t[ordinaryStop + 1] != QLatin1Char('\\'))
--ordinaryStop;
if ((ordinaryStop + 1 - start) * 2 >= stop - start)
stop = ordinaryStop;
}
if (!preview) {
const int y = (bounds.top() + bounds.bottom()) / 2 - 10 * nLines + 20 * line - 1;
if (dot)
sprite(canvas, *HGrSystem, bounds.left() + PaperBorder_Left + (ListIndent - 14), y + 7, 8, 8, 90,
16);
const QString s = t.mid(start, stop - start + 1);
biColorTextOut(canvas, Colors->image().pixelColor(clkMisc, cliPaperText), colorFromDelphi(0x7F007F),
bounds.left() + PaperBorder_Left + indent, y, s);
}
++line;
start = stop + 2;
}
nLines = line;
}
}
void NegoDlg::closeEvent(QCloseEvent *event)
{
BufferedDrawDlg::closeEvent(event);
}
void NegoDlg::mousePressEvent(QMouseEvent *event)
{
const int x = event->position().toPoint().x();
const int y = event->position().toPoint().y();
if (x >= xNationPicture0 && x < xNationPicture0 + 64 && y >= yNationPicture && y < yNationPicture + 48) {
if (auto *dlg = Term::mainScreenNatStatDlg())
dlg->showNewContent(windowModeMakePersistent(windowMode()),
Term::dipMem[static_cast<std::size_t>(ClientTools::me)].pContact);
} else if (x >= xNationPicture1 && x < xNationPicture1 + 64 && y >= yNationPicture && y < yNationPicture + 48) {
if (auto *dlg = Term::mainScreenNatStatDlg())
dlg->showNewContent(windowModeMakePersistent(windowMode()), ClientTools::me);
}
}
void NegoDlg::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
if (ui->okBtn->isVisible())
ui->okBtn->onClick();
} else {
BufferedDrawDlg::keyPressEvent(event);
}
}
void NegoDlg::wantClicked(int priceIndex)
{
const int me = ClientTools::me;
const int pContact = Term::dipMem[static_cast<std::size_t>(me)].pContact;
if (page != history[static_cast<std::size_t>(me)].n || IsoEngine::clientMode == scDipCancelTreaty ||
IsoEngine::clientMode == scDipBreak)
return;
std::uint32_t price;
if (costs[static_cast<std::size_t>(priceIndex)] != 0xFFFFFFFFu) {
price = 0xFFFFFFFFu; // toggle off
} else {
if (currentOffer.nCost >= 2) {
MessgEx::soundMessageEx(phrase(QStringLiteral("MAX2WANTS")), QString());
return;
}
price = ButtonPrice[static_cast<std::size_t>(priceIndex)];
if (!oppoAllowed.test(static_cast<std::size_t>(price >> 24)))
return;
switch (price) {
case static_cast<std::uint32_t>(opCivilReport):
case static_cast<std::uint32_t>(opMilReport):
price += static_cast<std::uint32_t>(pContact << 16) + static_cast<std::uint32_t>(ClientTools::myRO->Turn);
break;
case static_cast<std::uint32_t>(opMoney): {
InputDlg dlg;
dlg.setWindowTitle(phrase(QStringLiteral("TITLE_AMOUNT")));
dlg.editInput()->setText(QString());
dlg.centerToRect(geometry());
if (dlg.showModal() != Dpi::ModalResult::Ok)
return;
bool ok = false;
const int a = dlg.editInput()->text().toInt(&ok);
if (!ok || a <= 0 || a >= MaxMoneyPrice)
return;
price += static_cast<std::uint32_t>(a);
break;
}
case static_cast<std::uint32_t>(opShipParts): {
if (ClientTools::myRO->NatBuilt[imSpacePort] == 0) {
if (auto *dlg = Term::mainScreenMessgExDlg()) {
dlg->openSound = QStringLiteral("WARNING_LOWSUPPORT");
dlg->messageText = phrase(QStringLiteral("NOSPACEPORT"));
dlg->kind = MessageKind::YesNo;
dlg->iconKind = MessgEx::MessageIconKind::Imp;
dlg->iconIndex = imSpacePort;
if (dlg->showModal() != Dpi::ModalResult::Ok)
return;
}
}
auto *selectDlg = Term::mainScreenModalSelectDlg();
if (!selectDlg)
return;
selectDlg->showNewContent(WindowMode::Modal, Select::ListKind::EnemyShipPart);
if (selectDlg->result < 0)
return;
price += static_cast<std::uint32_t>(selectDlg->result << 16);
int max = ClientTools::myRO->Ship[pContact].Parts[selectDlg->result];
InputDlg amountDlg;
amountDlg.setWindowTitle(phrase(QStringLiteral("TITLE_NUMBER")));
amountDlg.editInput()->setText(QString());
amountDlg.centerToRect(geometry());
if (amountDlg.showModal() != Dpi::ModalResult::Ok)
return;
bool ok = false;
int a = amountDlg.editInput()->text().toInt(&ok);
if (!ok || a <= 0)
return;
if (a > max)
a = max;
if (a > MaxShipPartPrice)
a = MaxShipPartPrice;
price += static_cast<std::uint32_t>(a);
break;
}
case static_cast<std::uint32_t>(opAllTech): {
auto *selectDlg = Term::mainScreenModalSelectDlg();
if (!selectDlg)
return;
selectDlg->showNewContent(WindowMode::Modal, Select::ListKind::ChooseEnemyTech);
if (selectDlg->result < 0)
return;
price = selectDlg->result == Select::adAll
? static_cast<std::uint32_t>(opAllTech)
: static_cast<std::uint32_t>(opTech) + static_cast<std::uint32_t>(selectDlg->result);
break;
}
case static_cast<std::uint32_t>(opAllModel): {
auto *selectDlg = Term::mainScreenModalSelectDlg();
if (!selectDlg)
return;
selectDlg->showNewContent(WindowMode::Modal, Select::ListKind::ChooseEnemyModel);
if (selectDlg->result < 0)
return;
price = selectDlg->result == Select::mixAll
? static_cast<std::uint32_t>(opAllModel)
: static_cast<std::uint32_t>(opModel) +
static_cast<std::uint32_t>((*ClientTools::myRO->EnemyModel)[selectDlg->result].mix);
break;
}
case static_cast<std::uint32_t>(opTreaty):
price = ClientTools::myRO->Treaty[pContact] < trPeace
? static_cast<std::uint32_t>(opTreaty + trPeace)
: static_cast<std::uint32_t>(opTreaty + ClientTools::myRO->Treaty[pContact] + 1);
break;
default:
break;
}
}
costs[static_cast<std::size_t>(priceIndex)] = price;
buildCurrentOffer();
dipCommand = scDipOffer;
setButtonStates();
smartUpdateContent();
}
void NegoDlg::offerClicked(int priceIndex)
{
const int me = ClientTools::me;
const int pContact = Term::dipMem[static_cast<std::size_t>(me)].pContact;
if (page != history[static_cast<std::size_t>(me)].n || IsoEngine::clientMode == scDipCancelTreaty ||
IsoEngine::clientMode == scDipBreak)
return;
std::uint32_t price;
if (delivers[static_cast<std::size_t>(priceIndex)] != 0xFFFFFFFFu) {
price = 0xFFFFFFFFu; // toggle off
} else {
if (currentOffer.nDeliver >= 2) {
MessgEx::soundMessageEx(phrase(QStringLiteral("MAX2OFFERS")), QString());
return;
}
price = ButtonPrice[static_cast<std::size_t>(priceIndex)];
if (!myAllowed.test(static_cast<std::size_t>(price >> 24)))
return;
switch (price) {
case static_cast<std::uint32_t>(opCivilReport):
case static_cast<std::uint32_t>(opMilReport):
price += static_cast<std::uint32_t>(me << 16) + static_cast<std::uint32_t>(ClientTools::myRO->Turn);
break;
case static_cast<std::uint32_t>(opMoney): {
InputDlg dlg;
dlg.setWindowTitle(phrase(QStringLiteral("TITLE_AMOUNT")));
dlg.editInput()->setText(QString());
dlg.centerToRect(geometry());
if (dlg.showModal() != Dpi::ModalResult::Ok)
return;
bool ok = false;
int a = dlg.editInput()->text().toInt(&ok);
if (!ok || a <= 0 || a >= MaxMoneyPrice)
return;
if (a > ClientTools::myRO->Money)
a = ClientTools::myRO->Money;
price += static_cast<std::uint32_t>(a);
break;
}
case static_cast<std::uint32_t>(opShipParts): {
auto *selectDlg = Term::mainScreenModalSelectDlg();
if (!selectDlg)
return;
selectDlg->showNewContent(WindowMode::Modal, Select::ListKind::ShipPart);
if (selectDlg->result < 0)
return;
price += static_cast<std::uint32_t>(selectDlg->result << 16);
int max = ClientTools::myRO->Ship[me].Parts[selectDlg->result];
InputDlg amountDlg;
amountDlg.setWindowTitle(phrase(QStringLiteral("TITLE_NUMBER")));
amountDlg.editInput()->setText(QString());
amountDlg.centerToRect(geometry());
if (amountDlg.showModal() != Dpi::ModalResult::Ok)
return;
bool ok = false;
int a = amountDlg.editInput()->text().toInt(&ok);
if (!ok || a <= 0)
return;
if (a > max)
a = max;
if (a > MaxShipPartPrice)
a = MaxShipPartPrice;
price += static_cast<std::uint32_t>(a);
break;
}
case static_cast<std::uint32_t>(opAllTech): {
auto *selectDlg = Term::mainScreenModalSelectDlg();
if (!selectDlg)
return;
selectDlg->showNewContent(WindowMode::Modal, Select::ListKind::ChooseTech);
if (selectDlg->result < 0)
return;
price = selectDlg->result == Select::adAll
? static_cast<std::uint32_t>(opAllTech)
: static_cast<std::uint32_t>(opTech) + static_cast<std::uint32_t>(selectDlg->result);
break;
}
case static_cast<std::uint32_t>(opAllModel): {
auto *selectDlg = Term::mainScreenModalSelectDlg();
if (!selectDlg)
return;
selectDlg->showNewContent(WindowMode::Modal, Select::ListKind::ChooseModel);
if (selectDlg->result < 0)
return;
price = selectDlg->result == Select::mixAll
? static_cast<std::uint32_t>(opAllModel)
: static_cast<std::uint32_t>(opModel) + static_cast<std::uint32_t>(selectDlg->result);
break;
}
case static_cast<std::uint32_t>(opTreaty):
price = ClientTools::myRO->Treaty[pContact] < trPeace
? static_cast<std::uint32_t>(opTreaty + trPeace)
: static_cast<std::uint32_t>(opTreaty + ClientTools::myRO->Treaty[pContact] + 1);
break;
default:
break;
}
}
delivers[static_cast<std::size_t>(priceIndex)] = price;
buildCurrentOffer();
dipCommand = scDipOffer;
setButtonStates();
smartUpdateContent();
}
void NegoDlg::fastClicked(int commandOffset)
{
if (page != history[static_cast<std::size_t>(ClientTools::me)].n)
return;
const int newCommand = commandOffset + scDipStart;
if (!commandAllowed.test(static_cast<std::size_t>(commandOffset)))
return;
if (newCommand == scDipCancelTreaty &&
ClientTools::myRO->Turn <
ClientTools::myRO->LastCancelTreaty[Term::dipMem[static_cast<std::size_t>(ClientTools::me)].pContact] +
CancelTreatyTurns) {
MessgEx::soundMessageEx(phrase(QStringLiteral("CANCELTREATYRUSH")), QString());
return;
}
if (newCommand == scDipOffer && (IsoEngine::clientMode == scDipCancelTreaty || IsoEngine::clientMode == scDipBreak))
dipCommand = scDipNotice;
else
dipCommand = newCommand;
resetCurrentOffer();
setButtonStates();
smartUpdateContent();
}
} // namespace Nego
} // namespace Cevo
+104
View File
@@ -0,0 +1,104 @@
// 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.
#pragma once
#include "Cevo/CevoBaseWin.h"
#include "Cevo/Protocol.h"
#include <array>
#include <bitset>
#include <cstdint>
QT_BEGIN_NAMESPACE
namespace Ui {
class NegoDlg;
}
QT_END_NAMESPACE
namespace Cevo {
class ButtonN;
namespace Nego {
constexpr int MaxHistory = 62;
// THistory equivalent: one negotiation session's turn-by-turn log text.
struct History {
int n = 0;
std::array<QString, MaxHistory> text;
};
// TNegoDlg equivalent: the diplomacy negotiation screen (want/offer button
// grid, history pages, current-offer building).
class NegoDlg : public BufferedDrawDlg {
Q_OBJECT
public:
explicit NegoDlg(QWidget *parent = nullptr);
~NegoDlg() override;
void initiate(); // first turn of negotiation, initiate
void respond(); // first turn of negotiation, respond
void start(); // next turn of negotiation
void offscreenPaint() override;
void showNewContent(WindowMode newMode);
protected:
void closeEvent(QCloseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private:
void resetCurrentOffer();
void buildCurrentOffer();
void findAllowed();
void splitText(const QString &text, const QRect &bounds);
void paintNationPicture(int x, int y, int p);
void setButtonStates();
void wantClicked(int priceIndex);
void offerClicked(int priceIndex);
void fastClicked(int commandOffset);
int page = 0;
int dipCommand = -1;
TOffer currentOffer{};
std::bitset<256> myAllowed;
std::bitset<256> oppoAllowed;
std::bitset<256> commandAllowed; // indexed by (scDipXxx - scDipStart)
std::array<History, nPl> history;
Dpi::Font romanFont;
std::array<std::uint32_t, 12> costs{};
std::array<std::uint32_t, 12> delivers{};
std::array<ButtonN *, 12> wantButtons{};
std::array<ButtonN *, 12> offerButtons{};
Ui::NegoDlg *ui;
};
} // namespace Nego
} // namespace Cevo
+165
View File
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<ui version="4.0">
<class>NegoDlg</class>
<widget class="QWidget" name="NegoDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="windowTitle">
<string>C-evo</string>
</property>
<widget class="Cevo::ButtonA" name="okBtn">
<property name="geometry">
<rect><x>426</x><y>446</y><width>100</width><height>25</height></rect>
</property>
</widget>
<widget class="Cevo::ButtonB" name="bwdBtn">
<property name="geometry">
<rect><x>13</x><y>446</y><width>25</width><height>25</height></rect>
</property>
</widget>
<widget class="Cevo::ButtonB" name="fwdBtn">
<property name="geometry">
<rect><x>602</x><y>446</y><width>25</width><height>25</height></rect>
</property>
</widget>
<widget class="Cevo::ButtonB" name="closeBtn">
<property name="geometry">
<rect><x>602</x><y>6</y><width>25</width><height>25</height></rect>
</property>
</widget>
<widget class="Cevo::ButtonN" name="wantAnythingBtn">
<property name="geometry"><rect><x>139</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantStateReportBtn">
<property name="geometry"><rect><x>181</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantMilReportBtn">
<property name="geometry"><rect><x>223</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantMapBtn">
<property name="geometry"><rect><x>265</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantTech1Btn">
<property name="geometry"><rect><x>139</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantTech2Btn">
<property name="geometry"><rect><x>181</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantModelBtn">
<property name="geometry"><rect><x>223</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantMoneyBtn">
<property name="geometry"><rect><x>265</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantHiTreatyBtn">
<property name="geometry"><rect><x>139</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantLoTreatyBtn">
<property name="geometry"><rect><x>181</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantShipPart1Btn">
<property name="geometry"><rect><x>223</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="wantShipPart2Btn">
<property name="geometry"><rect><x>265</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerAnythingBtn">
<property name="geometry"><rect><x>333</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerStateReportBtn">
<property name="geometry"><rect><x>375</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerMilReportBtn">
<property name="geometry"><rect><x>417</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerMapBtn">
<property name="geometry"><rect><x>459</x><y>12</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerTech1Btn">
<property name="geometry"><rect><x>333</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerTech2Btn">
<property name="geometry"><rect><x>375</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerModelBtn">
<property name="geometry"><rect><x>417</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerMoneyBtn">
<property name="geometry"><rect><x>459</x><y>54</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerHiTreatyBtn">
<property name="geometry"><rect><x>333</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerLoTreatyBtn">
<property name="geometry"><rect><x>375</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerShipPart1Btn">
<property name="geometry"><rect><x>417</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="offerShipPart2Btn">
<property name="geometry"><rect><x>459</x><y>96</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="acceptBtn">
<property name="geometry"><rect><x>139</x><y>426</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="passBtn">
<property name="geometry"><rect><x>181</x><y>426</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="exitBtn">
<property name="geometry"><rect><x>223</x><y>426</y><width>42</width><height>42</height></rect></property>
</widget>
<widget class="Cevo::ButtonN" name="cancelTreatyBtn">
<property name="geometry"><rect><x>265</x><y>426</y><width>42</width><height>42</height></rect></property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Cevo::ButtonA</class>
<extends>QWidget</extends>
<header>Cevo/CevoButtonA.h</header>
</customwidget>
<customwidget>
<class>Cevo::ButtonB</class>
<extends>QWidget</extends>
<header>Cevo/CevoButtonB.h</header>
</customwidget>
<customwidget>
<class>Cevo::ButtonN</class>
<extends>QWidget</extends>
<header>Cevo/CevoButtonN.h</header>
</customwidget>
</customwidgets>
<resources/>
</ui>
+4
View File
@@ -175,6 +175,10 @@ std::function<void()> mainScreenRepaintAll = [] {};
std::function<int(int)> modalSelectDlgShowCityProject = [](int) { return -1; };
std::function<bool(int)> listDlgRenameCity = [](int) { return false; };
std::function<MessgEx::MessgExDlg *()> mainScreenMessgExDlg = [] { return static_cast<MessgEx::MessgExDlg *>(nullptr); };
std::function<Select::ListDlg *()> mainScreenModalSelectDlg = [] { return static_cast<Select::ListDlg *>(nullptr); };
std::function<NatStat::NatStatDlg *()> mainScreenNatStatDlg = [] { return static_cast<NatStat::NatStatDlg *>(nullptr); };
std::function<int(const TOffer &)> mainScreenOfferCall = [](const TOffer &) { return eInvalid; };
TOffer receivedOffer{};
} // namespace Term
} // namespace Cevo
+23 -2
View File
@@ -33,10 +33,13 @@
#include "Cevo/Protocol.h"
#include "ClientTools.h"
#include "MessgEx.h"
#include "NatStat.h"
#include "Select.h"
#include <QString>
#include <array>
#include <bitset>
#include <cstdint>
#include <functional>
@@ -109,13 +112,23 @@ extern ClientTools::SaveOptions optionChecked;
// just observing rather than playing a nation).
extern bool supervising;
// Term.pas's `TDipMem` (per-nation negotiation session memory) - only the
// one field (`pContact`) anything needs so far.
// Term.pas's `TDipMem` (per-nation negotiation session memory).
struct DipMemEntry {
int pContact = -1;
// Nego.pas's own negotiation-session bookkeeping (added for Nego.pas).
int formerTreaty = trNone;
int sentCommand = 0;
TOffer sentOffer{};
// TPriceSet = set of $00..$FF (price-category bytes, i.e. opXxx >> 24).
std::bitset<256> deliveredPrices;
std::bitset<256> receivedPrices;
};
extern std::array<DipMemEntry, nPl> dipMem;
// Term.pas's `ReceivedOffer: TOffer;` (the opponent's current negotiation
// offer, as last received from the server).
extern TOffer receivedOffer;
// Term.pas's RoughCredibility(): buckets a 0..100 credibility value into a
// 4-level rating (0..3) for display.
int roughCredibility(int credibility);
@@ -227,6 +240,14 @@ extern std::function<bool(int cix)> listDlgRenameCity;
// Mirrors `MainScreen.MessgExDlg` dialog access - returns nullptr by
// default until Term.pas creates a real instance.
extern std::function<MessgEx::MessgExDlg *()> mainScreenMessgExDlg;
// Mirrors `MainScreen.ModalSelectDlg`/`MainScreen.NatStatDlg` dialog
// access (the general, non-city-project form - see also
// modalSelectDlgShowCityProject above for the city-project-only variant).
extern std::function<Select::ListDlg *()> mainScreenModalSelectDlg;
extern std::function<NatStat::NatStatDlg *()> mainScreenNatStatDlg;
// Mirrors `MainScreen.OfferCall(var Offer: TOffer): Integer` - returns
// eInvalid by default.
extern std::function<int(const TOffer &offer)> mainScreenOfferCall;
} // namespace Term
} // namespace Cevo