multiple sparce implementations for main window
This commit is contained in:
1 parent
8e7d483471
commit
e59988ab1d
9 files changed
+1091
-25
No files matched your search
+259
-6
@@ -28,11 +28,17 @@
|
||||
|
||||
#include "Term.h"
|
||||
|
||||
#include "Cevo/CmdList.h"
|
||||
#include "Global.h"
|
||||
#include "Help.h"
|
||||
#include "IsoEngine.h"
|
||||
#include "Tribes.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace Cevo {
|
||||
namespace Term {
|
||||
|
||||
@@ -81,15 +87,39 @@ void impImage(Dpi::Canvas &canvas, int x, int y, int iix, int government, bool i
|
||||
|
||||
void chooseModelPicture(int p, int mix, int code, int hash, int turn, bool forceNew, bool final)
|
||||
{
|
||||
const auto player = static_cast<std::size_t>(p);
|
||||
Tribes::ModelPictureInfo picture;
|
||||
picture.trix = p;
|
||||
picture.mix = mix;
|
||||
picture.hash = hash;
|
||||
const bool isNew = Tribes::tribe[static_cast<std::size_t>(p)]->chooseModelPicture(picture, code, turn, forceNew);
|
||||
if (final) {
|
||||
Tribes::tribe[static_cast<std::size_t>(p)]->setModelPicture(picture, isNew);
|
||||
bool isNew;
|
||||
if (code == 74) { // use correct pictures for slaves
|
||||
if (Tribes::tribe[player]->mixSlaves < 0) {
|
||||
if (!tribeOriginal[player]) {
|
||||
Tribes::tribe[player]->mixSlaves = mix;
|
||||
} else {
|
||||
int data = mix + (p << 16);
|
||||
ClientTools::server(cSetSlaveIndex, 0, 0, &data);
|
||||
}
|
||||
}
|
||||
picture.pix = toldSlavery == 1 ? pixSlaves : pixNoSlaves;
|
||||
picture.hash = 0;
|
||||
picture.grName = QStringLiteral("StdUnits");
|
||||
isNew = true;
|
||||
} else {
|
||||
Tribes::ModelPicture &mp = Tribes::tribe[static_cast<std::size_t>(p)]->modelPictureAt(mix);
|
||||
picture.hash = hash;
|
||||
isNew = Tribes::tribe[player]->chooseModelPicture(picture, code, turn, forceNew);
|
||||
}
|
||||
if (final) {
|
||||
if (!tribeOriginal[player]) {
|
||||
Tribes::tribe[player]->setModelPicture(picture, isNew);
|
||||
} else {
|
||||
QByteArray data = packModelPictureInfo(picture);
|
||||
ClientTools::server(commandWithData(isNew ? cSetNewModelPicture : cSetModelPicture,
|
||||
picture.commandDataSize()),
|
||||
0, 0, data.data());
|
||||
}
|
||||
} else {
|
||||
Tribes::ModelPicture &mp = Tribes::tribe[player]->modelPictureAt(mix);
|
||||
mp.hGr = loadGraphicSet(picture.grName);
|
||||
mp.pix = picture.pix;
|
||||
}
|
||||
@@ -97,6 +127,9 @@ void chooseModelPicture(int p, int mix, int code, int hash, int turn, bool force
|
||||
|
||||
void initMyModel(int mix, bool final)
|
||||
{
|
||||
// special models (Kind >= $08) still get a picture: cSetModelPicture comes after tellNewModels()
|
||||
if (gameMode == cMovie && ClientTools::myModel[mix].Kind < 0x08)
|
||||
return;
|
||||
TModelInfo mi{};
|
||||
MakeModelInfo(ClientTools::me, mix, ClientTools::myModel[mix], mi);
|
||||
chooseModelPicture(ClientTools::me, mix, Tribes::modelCode(mi), ClientTools::modelHash(mi),
|
||||
@@ -114,7 +147,222 @@ std::array<int, nAdv> advIcon = [] {
|
||||
}();
|
||||
std::array<int, nPl * nMmax> lostArmy{};
|
||||
int nLostArmy = 0;
|
||||
std::function<void()> initAllEnemyModels = [] {};
|
||||
|
||||
bool initEnemyModel(int emix)
|
||||
{
|
||||
if (gameMode == cMovie)
|
||||
return false;
|
||||
const TModelInfo &enemyModel = (*ClientTools::myRO->EnemyModel)[emix];
|
||||
chooseModelPicture(enemyModel.Owner, enemyModel.mix, Tribes::modelCode(enemyModel),
|
||||
ClientTools::modelHash(enemyModel), ClientTools::myRO->Turn, false, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
void initAllEnemyModels()
|
||||
{
|
||||
for (int emix = 0; emix < ClientTools::myRO->nEnemyModel; ++emix) {
|
||||
const TModelInfo &enemyModel = (*ClientTools::myRO->EnemyModel)[emix];
|
||||
if (!Tribes::tribe[static_cast<std::size_t>(enemyModel.Owner)]->modelPictureAt(enemyModel.mix).hGr)
|
||||
initEnemyModel(emix);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void appendInt32(QByteArray &data, int value)
|
||||
{
|
||||
const auto v = static_cast<std::int32_t>(value);
|
||||
data.append(reinterpret_cast<const char *>(&v), sizeof v);
|
||||
}
|
||||
|
||||
// Pascal ShortString: length byte followed by the bytes.
|
||||
void appendShortString(QByteArray &data, const QString &text)
|
||||
{
|
||||
QByteArray bytes = text.toUtf8();
|
||||
bytes.truncate(255);
|
||||
data.append(static_cast<char>(bytes.size()));
|
||||
data.append(bytes);
|
||||
}
|
||||
|
||||
std::uint8_t shortStringRecordSize(const QString &text)
|
||||
{
|
||||
return static_cast<std::uint8_t>(sizeof(std::int32_t) + 1 + std::min<qsizetype>(255, text.toUtf8().size()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
QByteArray TribeInfo::pack() const
|
||||
{
|
||||
QByteArray data;
|
||||
appendInt32(data, trix);
|
||||
appendShortString(data, fileName);
|
||||
return data;
|
||||
}
|
||||
|
||||
std::uint8_t TribeInfo::commandDataSize() const { return shortStringRecordSize(fileName); }
|
||||
|
||||
QByteArray CityNameInfo::pack() const
|
||||
{
|
||||
QByteArray data;
|
||||
appendInt32(data, id);
|
||||
appendShortString(data, newName);
|
||||
return data;
|
||||
}
|
||||
|
||||
std::uint8_t CityNameInfo::commandDataSize() const { return shortStringRecordSize(newName); }
|
||||
|
||||
QByteArray ModelNameInfo::pack() const
|
||||
{
|
||||
QByteArray data;
|
||||
appendInt32(data, mix);
|
||||
appendShortString(data, newName);
|
||||
return data;
|
||||
}
|
||||
|
||||
std::uint8_t ModelNameInfo::commandDataSize() const { return shortStringRecordSize(newName); }
|
||||
|
||||
QByteArray packModelPictureInfo(const Tribes::ModelPictureInfo &info)
|
||||
{
|
||||
QByteArray data;
|
||||
appendInt32(data, info.trix);
|
||||
appendInt32(data, info.mix);
|
||||
appendInt32(data, info.pix);
|
||||
appendInt32(data, info.hash);
|
||||
appendShortString(data, info.grName);
|
||||
return data;
|
||||
}
|
||||
|
||||
Tribes::ModelPictureInfo unpackModelPictureInfo(const void *data)
|
||||
{
|
||||
const auto *bytes = static_cast<const unsigned char *>(data);
|
||||
std::int32_t fields[4];
|
||||
std::memcpy(fields, bytes, sizeof fields);
|
||||
Tribes::ModelPictureInfo info;
|
||||
info.trix = fields[0];
|
||||
info.mix = fields[1];
|
||||
info.pix = fields[2];
|
||||
info.hash = fields[3];
|
||||
const unsigned char length = bytes[sizeof fields];
|
||||
info.grName = QString::fromUtf8(reinterpret_cast<const char *>(bytes + sizeof fields + 1), length);
|
||||
return info;
|
||||
}
|
||||
|
||||
std::array<bool, nPl> tribeOriginal{};
|
||||
int toldSlavery = 0;
|
||||
|
||||
QString attackSound(int code)
|
||||
{
|
||||
return QStringLiteral("ATTACK_%1%2%3").arg(code / 100 % 10).arg(code / 10 % 10).arg(code % 10);
|
||||
}
|
||||
|
||||
int alignUp(int value, int alignment) { return value | (alignment - 1); }
|
||||
|
||||
void initSmallImp()
|
||||
{
|
||||
static Dpi::Bitmap storage;
|
||||
smallImp = &storage;
|
||||
if (!bigImp)
|
||||
return;
|
||||
smallImp->setSize(bigImp->width() * xSizeSmall / xSizeBig, bigImp->height() * ySizeSmall / ySizeBig);
|
||||
smallImp->canvas().stretchDraw(QRect(0, 0, smallImp->width(), smallImp->height()), bigImp->image());
|
||||
}
|
||||
|
||||
void checkToldNoReturn(int uix)
|
||||
{
|
||||
// check whether aircraft survived low-fuel warning
|
||||
Q_ASSERT(!supervising);
|
||||
TUn &un = ClientTools::myUn[uix];
|
||||
if ((un.Status & usToldNoReturn) &&
|
||||
((ClientTools::myMap[un.Loc] & fCity) || (ClientTools::myMap[un.Loc] & fTerImp) == tiBase || un.Master >= 0))
|
||||
un.Status &= ~usToldNoReturn;
|
||||
}
|
||||
|
||||
bool createTribe(int p, QString fileName, bool original)
|
||||
{
|
||||
fileName = localizedFilePath(QStringLiteral("Tribes/") + fileName + QLatin1String(CevoTribeExt));
|
||||
if (!QFile::exists(fileName))
|
||||
return false;
|
||||
|
||||
const auto player = static_cast<std::size_t>(p);
|
||||
tribeOriginal[player] = original;
|
||||
Tribes::tribe[player] = std::make_unique<Tribes::Tribe>(fileName);
|
||||
if (gameMode == cNewGame || !original) {
|
||||
chooseModelPicture(p, 0, 010, 1, 0, true, true);
|
||||
chooseModelPicture(p, 1, 040, 1, 0, true, true);
|
||||
chooseModelPicture(p, 2, 041, 1, 0, true, true);
|
||||
chooseModelPicture(p, -1, 017, 1, 0, true, true);
|
||||
}
|
||||
dipMem[player].pContact = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void tellNewContacts()
|
||||
{
|
||||
if (supervising)
|
||||
return;
|
||||
for (int p1 = 0; p1 < nPl; ++p1) {
|
||||
if (p1 != ClientTools::me && !(myData->toldContact & (1 << p1)) &&
|
||||
(ClientTools::myRO->Alive & (1 << p1)) && ClientTools::myRO->Treaty[p1] > trNoContact) {
|
||||
MessgEx::tribeMessage(p1, Tribes::tribe[static_cast<std::size_t>(p1)]->tPhrase(QStringLiteral("FRNEWNATION")),
|
||||
QString());
|
||||
myData->toldContact |= 1 << p1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tellNewModels()
|
||||
{
|
||||
if (supervising)
|
||||
return;
|
||||
Tribes::Tribe &myTribe = *Tribes::tribe[static_cast<std::size_t>(ClientTools::me)];
|
||||
while (myData->toldModels < ClientTools::myRO->nModel) { // new unit class available
|
||||
const int told = myData->toldModels;
|
||||
if (myTribe.modelPictureAt(told).hGr && ClientTools::myModel[told].Kind != mkSelfDeveloped) {
|
||||
// save picture of DevModel
|
||||
myTribe.modelPictureAt(told + 1) = myTribe.modelPictureAt(told);
|
||||
myTribe.modelNameAt(told + 1) = myTribe.modelNameAt(told);
|
||||
myTribe.modelPictureAt(told).hGr = nullptr;
|
||||
}
|
||||
if (!myTribe.modelPictureAt(told).hGr)
|
||||
initMyModel(told, true);
|
||||
// only run if no researched model
|
||||
MessgEx::MessgExDlg *dlg = mainScreenMessgExDlg();
|
||||
if (dlg) {
|
||||
if (ClientTools::myModel[told].Kind == mkSelfDeveloped)
|
||||
dlg->openSound = QStringLiteral("NEWMODEL_%1").arg(age);
|
||||
// TODO: Phrases['MODELAVAILABLE'] (StringTables.pas not ported) - plain English fallback.
|
||||
dlg->messageText = QStringLiteral("New units are ready for production.");
|
||||
if (gameMode == cMovie) {
|
||||
dlg->kind = MessageKind::OkHelp; // doesn't matter
|
||||
dlg->messageText += QLatin1Char('\\') + myTribe.modelNameAt(told);
|
||||
} else {
|
||||
dlg->kind = MessageKind::Model;
|
||||
dlg->setInputText(myTribe.modelNameAt(told));
|
||||
}
|
||||
dlg->iconKind = MessgEx::MessageIconKind::Model;
|
||||
dlg->iconIndex = told;
|
||||
dlg->showModal();
|
||||
const QString newName = dlg->inputText();
|
||||
if (!newName.isEmpty() && newName != myTribe.modelNameAt(told)) { // user renamed model
|
||||
ModelNameInfo info;
|
||||
info.mix = told;
|
||||
info.newName = newName;
|
||||
while (info.commandDataSize() > CommandDataMaxSize && !info.newName.isEmpty())
|
||||
info.newName.chop(1);
|
||||
QByteArray data = info.pack();
|
||||
ClientTools::server(commandWithData(cSetModelName, info.commandDataSize()), ClientTools::me, 0,
|
||||
data.data());
|
||||
}
|
||||
}
|
||||
if (ClientTools::myModel[told].Kind == mkSettler) { // engineers make settlers obsolete
|
||||
for (int mix = 0; mix < told; ++mix) {
|
||||
if (ClientTools::myModel[mix].Kind == mkSettler)
|
||||
ClientTools::myModel[mix].Status |= msObsolete;
|
||||
}
|
||||
}
|
||||
++myData->toldModels;
|
||||
}
|
||||
}
|
||||
|
||||
const std::array<int, nCityEventPriority> CityEventPriority = {
|
||||
chDisorder, chImprovementLost, chUnitLost, chAllImpsMade,
|
||||
@@ -180,5 +428,10 @@ std::function<NatStat::NatStatDlg *()> mainScreenNatStatDlg = [] { return static
|
||||
std::function<int(const TOffer &)> mainScreenOfferCall = [](const TOffer &) { return eInvalid; };
|
||||
TOffer receivedOffer{};
|
||||
|
||||
int taxSum = 0;
|
||||
int scienceSum = 0;
|
||||
std::vector<UnusedTribe> unusedTribeFiles;
|
||||
MainScreen *mainScreen = nullptr;
|
||||
|
||||
} // namespace Term
|
||||
} // namespace Cevo
|
||||
Reference in new issue
Block a user