add back and splitted database
This commit is contained in:
1 parent
a7e65be715
commit
55ccee5b57
16 files changed
+3215
-2534
No files matched your search
@@ -0,0 +1,222 @@
|
||||
// This file is part of cevo-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.
|
||||
|
||||
// --- Tech Related Functions --- (see Cevo/Database.h)
|
||||
|
||||
#include "Cevo/Database.h"
|
||||
#include "DatabaseInternal.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace Cevo {
|
||||
namespace Database {
|
||||
|
||||
// Equivalent of Database.pas's private FreeSlaves().
|
||||
void freeSlaves()
|
||||
{
|
||||
for (int p1 = 0; p1 < nPl; ++p1) {
|
||||
if (gAlive & (1 << p1)) {
|
||||
TUn *un = *rw[p1].Un;
|
||||
const TModel *model = *rw[p1].Model;
|
||||
for (int uix = 0; uix < rw[p1].nUn; ++uix)
|
||||
if (model[un[uix].mix].Kind == mkSlaves)
|
||||
un[uix].Job = jNone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int techBaseCost(int nTech, int diff)
|
||||
{
|
||||
const double c0 = TechFormula_M[diff] * (nTech + 4) * std::exp((nTech + 4) / TechFormula_D[diff]);
|
||||
if (c0 >= 0x10000000)
|
||||
return 0x10000000;
|
||||
return static_cast<int>(c0); // truncates toward zero, matching Pascal's Trunc()
|
||||
}
|
||||
|
||||
void setModelFlags(TModel &m)
|
||||
{
|
||||
m.Flags = 0;
|
||||
if (m.Domain == dGround && m.Kind != mkDiplomat)
|
||||
m.Flags |= mdZOC;
|
||||
if (m.Kind == mkDiplomat || m.Attack + m.Cap[mcBombs] == 0)
|
||||
m.Flags |= mdCivil;
|
||||
if (m.Cap[mcOver] > 0 || (m.Domain == dSea && m.Weight >= 6))
|
||||
m.Flags |= mdDoubleSupport;
|
||||
}
|
||||
|
||||
void calculateModel(TModel &m)
|
||||
{
|
||||
m.Attack = static_cast<decltype(m.Attack)>((m.Cap[mcOffense] + m.Cap[mcOver]) * m.MStrength);
|
||||
m.Defense = static_cast<decltype(m.Defense)>((m.Cap[mcDefense] + m.Cap[mcOver]) * m.MStrength);
|
||||
switch (m.Domain) {
|
||||
case dGround:
|
||||
m.Speed = static_cast<decltype(m.Speed)>(150 + m.Cap[mcMob] * 50);
|
||||
break;
|
||||
case dSea:
|
||||
m.Speed = static_cast<decltype(m.Speed)>(350 + 200 * m.Cap[mcNP] + 200 * m.Cap[mcTurbines]);
|
||||
if (m.Cap[mcNP] == 0)
|
||||
m.Speed = static_cast<decltype(m.Speed)>(m.Speed + 100 * m.Cap[mcSE]);
|
||||
break;
|
||||
case dAir:
|
||||
m.Speed = static_cast<decltype(m.Speed)>(850 + 400 * m.Cap[mcJet]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
int cost = 0;
|
||||
for (int i = 0; i < nFeature; ++i)
|
||||
if ((1 << m.Domain) & Feature[i].Domains)
|
||||
cost += m.Cap[i] * Feature[i].Cost;
|
||||
m.Cost = static_cast<decltype(m.Cost)>(cost * m.MCost);
|
||||
int weight = 0;
|
||||
for (int i = 0; i < nFeature; ++i)
|
||||
if ((1 << m.Domain) & Feature[i].Domains)
|
||||
weight += (m.Domain == dGround && i == mcDefense) ? m.Cap[i] * 2 : m.Cap[i] * Feature[i].Weight;
|
||||
m.Weight = static_cast<decltype(m.Weight)>(weight);
|
||||
setModelFlags(m);
|
||||
}
|
||||
|
||||
void checkSpecialModels(int p, int pre)
|
||||
{
|
||||
TPlayerContext &player = rw[p];
|
||||
TModel *model = *player.Model;
|
||||
for (int i = 0; i < nSpecialModel; ++i) {
|
||||
if (SpecialModelPreq[i] != pre || player.nModel >= nMmax)
|
||||
continue;
|
||||
bool hasAlready = false;
|
||||
for (int mix1 = 0; mix1 < player.nModel; ++mix1)
|
||||
if (model[mix1].Kind == SpecialModel[i].Kind && model[mix1].Attack == SpecialModel[i].Attack &&
|
||||
model[mix1].Speed == SpecialModel[i].Speed)
|
||||
hasAlready = true;
|
||||
if (!hasAlready) {
|
||||
model[player.nModel] = SpecialModel[i];
|
||||
setModelFlags(model[player.nModel]);
|
||||
TModel &newModel = model[player.nModel];
|
||||
newModel.Status = 0;
|
||||
newModel.SavedStatus = 0;
|
||||
newModel.IntroTurn = static_cast<std::uint16_t>(gTurn);
|
||||
newModel.Built = 0;
|
||||
newModel.Lost = 0;
|
||||
newModel.ID = static_cast<std::uint16_t>((p << 12) + player.nModel);
|
||||
if (newModel.Kind == mkSpecial_Boat && serverVersion[p] < 0x000EF0)
|
||||
newModel.Speed = 350; // old longboat
|
||||
++player.nModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void checkExpiration(int wonder)
|
||||
{
|
||||
// GWonder[wonder].EffectiveOwner must be set before!
|
||||
if (Imp[wonder].Expiration >= 0 && gWonder[woEiffel].EffectiveOwner != gWonder[wonder].EffectiveOwner) {
|
||||
for (int p = 0; p < nPl; ++p) {
|
||||
// check if already expired
|
||||
if ((gAlive & (1 << p)) && rw[p].Tech[Imp[wonder].Expiration] >= tsApplicable) {
|
||||
gWonder[wonder].EffectiveOwner = -1;
|
||||
if (wonder == woPyramids)
|
||||
freeSlaves();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void seeTech(int p, int ad)
|
||||
{
|
||||
rw[p].Tech[ad] = tsSeen;
|
||||
++researched[p];
|
||||
}
|
||||
|
||||
namespace {
|
||||
void tellAboutKeyTech(int p, int source, int ad)
|
||||
{
|
||||
for (int i = 1; i <= 3; ++i)
|
||||
if (ad == AgePreq[i])
|
||||
for (int p1 = 0; p1 < nPl; ++p1)
|
||||
if (p1 != p && ((gAlive | gWatching) & (1 << p1)))
|
||||
rw[p1].EnemyReport[p]->Tech[ad] = static_cast<std::int8_t>(source);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void discoverTech(int p, int ad)
|
||||
{
|
||||
TPlayerContext &player = rw[p];
|
||||
if (IsFutureTech(ad)) {
|
||||
if (player.Tech[ad] < tsApplicable)
|
||||
player.Tech[ad] = 1;
|
||||
else
|
||||
++player.Tech[ad];
|
||||
if (ad != futResearchTechnology)
|
||||
nTech[p] += 2;
|
||||
researched[p] += 8;
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.Tech[ad] == tsSeen) {
|
||||
++nTech[p];
|
||||
++researched[p];
|
||||
} else {
|
||||
nTech[p] += 2;
|
||||
researched[p] += 2;
|
||||
}
|
||||
player.Tech[ad] = tsResearched;
|
||||
tellAboutKeyTech(p, tsResearched, ad);
|
||||
checkSpecialModels(p, ad);
|
||||
if (ad == adScience)
|
||||
resourceMask[p] |= fSpecial2;
|
||||
if (ad == adMassProduction)
|
||||
resourceMask[p] |= fModern;
|
||||
|
||||
for (int i = 0; i < nWonder; ++i) { // check whether wonders expired
|
||||
if (gWonder[i].EffectiveOwner != gWonder[woEiffel].EffectiveOwner && Imp[i].Expiration == ad) {
|
||||
gWonder[i].EffectiveOwner = -1;
|
||||
if (i == woPyramids)
|
||||
freeSlaves();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void enableDevModel(int p)
|
||||
{
|
||||
TPlayerContext &player = rw[p];
|
||||
if (player.nModel >= nMmax)
|
||||
return;
|
||||
TModel *model = *player.Model;
|
||||
model[player.nModel] = player.DevModel;
|
||||
TModel &newModel = model[player.nModel];
|
||||
newModel.Status = 0;
|
||||
newModel.SavedStatus = 0;
|
||||
newModel.IntroTurn = static_cast<std::uint16_t>(gTurn);
|
||||
newModel.Built = 0;
|
||||
newModel.Lost = 0;
|
||||
newModel.ID = static_cast<std::uint16_t>((p << 12) + player.nModel);
|
||||
++player.nModel;
|
||||
++researched[p];
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
} // namespace Cevo
|
||||
Reference in new issue
Block a user