implemented map generator
This commit is contained in:
1 parent
69700f8b65
commit
f32cce0e56
9 files changed
+910
-38
No files matched your search
+32
-17
@@ -54,6 +54,15 @@
|
||||
namespace Cevo {
|
||||
namespace GameServer {
|
||||
|
||||
namespace {
|
||||
// The original's `Integer(Data)` on its untyped `var Data` parameter: the value stored at the address
|
||||
// the client passed (not the address itself).
|
||||
int dataValue(const void *data)
|
||||
{
|
||||
return data ? *static_cast<const int *>(data) : 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
// Equivalent of GameServer.pas's Server() - the client-to-server command
|
||||
// dispatcher. FULLY PORTED: Info Request, Map Editor (except sRandomMap,
|
||||
@@ -424,9 +433,15 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
break;
|
||||
|
||||
case sRandomMap:
|
||||
// TODO: needs CreateElevation/CreateMap (full procedural map
|
||||
// generator, not ported yet) - always reports unavailable for now.
|
||||
result = eInvalid;
|
||||
if (player == 0 && Database::mapGeneratorAvailable()) {
|
||||
Database::createElevation();
|
||||
previewElevation = false;
|
||||
Database::createMap(false);
|
||||
Database::observeLevel.fill(0);
|
||||
Database::discoverAll(player, Database::lObserveSuper);
|
||||
} else {
|
||||
result = eInvalid;
|
||||
}
|
||||
break;
|
||||
|
||||
case sFillMap:
|
||||
@@ -544,8 +559,8 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
bool ok;
|
||||
if (command == sReload) {
|
||||
ok = Database::difficulty[0] == 0 && playerBrain[0]->kind != BrainType::NoTerm &&
|
||||
reinterpret_cast<std::intptr_t>(data) >= 0 &&
|
||||
reinterpret_cast<std::intptr_t>(data) < Database::gTurn;
|
||||
dataValue(data) >= 0 &&
|
||||
dataValue(data) < Database::gTurn;
|
||||
for (int p1 = 1; p1 < nPl && ok; ++p1)
|
||||
if (playerBrain[p1] && playerBrain[p1]->kind == BrainType::Term)
|
||||
ok = false;
|
||||
@@ -582,7 +597,7 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
startNewGame(logFileName, mapFileName, Database::lx, Database::ly, Database::landMass, maxTurn);
|
||||
break;
|
||||
case sReload:
|
||||
loadGame(logFileName, logFileName, static_cast<int>(reinterpret_cast<std::intptr_t>(data)), false);
|
||||
loadGame(logFileName, logFileName, dataValue(data), false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -1071,12 +1086,12 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
result = eNoPreq;
|
||||
}
|
||||
}
|
||||
if (result == eOK && command >= sExecute) {
|
||||
if (Database::mode == Database::moPlaying && subject == adMilitary)
|
||||
Database::intServer(sIntSetDevModel, player, 0, &playerCtx.DevModel.Kind);
|
||||
// save DevModel, because sctModel commands are not Logged
|
||||
playerCtx.ResearchTech = subject;
|
||||
}
|
||||
}
|
||||
if (result == eOK && command >= sExecute) {
|
||||
if (Database::mode == Database::moPlaying && subject == adMilitary)
|
||||
Database::intServer(sIntSetDevModel, player, 0, &playerCtx.DevModel.Kind);
|
||||
// save DevModel, because sctModel commands are not Logged
|
||||
playerCtx.ResearchTech = subject;
|
||||
}
|
||||
} else {
|
||||
result = eViolation;
|
||||
@@ -1202,7 +1217,7 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
break;
|
||||
}
|
||||
TCity &city = (*playerCtx.City)[subject];
|
||||
const auto newProject = static_cast<std::int16_t>(reinterpret_cast<std::intptr_t>(data) & ~cpAuto);
|
||||
const auto newProject = static_cast<std::int16_t>(dataValue(data) & ~cpAuto);
|
||||
if (newProject == city.Project) {
|
||||
result = eNotChanged;
|
||||
break;
|
||||
@@ -1413,7 +1428,7 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
break;
|
||||
}
|
||||
TCity &city = (*playerCtx.City)[subject];
|
||||
const auto imp = static_cast<int>(reinterpret_cast<std::intptr_t>(data));
|
||||
const auto imp = dataValue(data);
|
||||
if (city.Built[imp] == 0) {
|
||||
result = eInvalid;
|
||||
} else if (playerCtx.Government == gAnarchy || (city.Flags & chCaptured)) {
|
||||
@@ -1442,7 +1457,7 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
result = eInvalid;
|
||||
break;
|
||||
}
|
||||
const auto oldImp = static_cast<int>(reinterpret_cast<std::intptr_t>(data));
|
||||
const auto oldImp = dataValue(data);
|
||||
TCity &city = (*playerCtx.City)[subject];
|
||||
if (oldImp < 0 || oldImp >= nImp ||
|
||||
!(Imp[oldImp].Kind == ikCommon || Imp[oldImp].Kind == ikNatLocal || Imp[oldImp].Kind == ikNatGlobal)) {
|
||||
@@ -1481,7 +1496,7 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
if (subject >= playerCtx.nCity || (*playerCtx.City)[subject].Loc < 0)
|
||||
result = eInvalid;
|
||||
else
|
||||
result = CityProcessing::setCityTiles(player, subject, static_cast<int>(reinterpret_cast<std::intptr_t>(data)),
|
||||
result = CityProcessing::setCityTiles(player, subject, dataValue(data),
|
||||
command < sExecute);
|
||||
break;
|
||||
}
|
||||
@@ -1626,7 +1641,7 @@ int CEVO_ABI_CALL server(int command, int player, int subject, void *data)
|
||||
}
|
||||
} else if ((command & ~0xF0) == sCreateUnit || (command & ~0xF0) == sCreateUnit - sExecute) {
|
||||
const int p1 = (command >> 4) & 0xF;
|
||||
const int loc1 = static_cast<int>(reinterpret_cast<std::intptr_t>(data));
|
||||
const int loc1 = dataValue(data);
|
||||
const TModel &model = (*Database::rw[p1].Model)[subject];
|
||||
if ((Database::occupant[loc1] >= 0 && p1 != Database::occupant[loc1]) ||
|
||||
((Database::realMap[loc1] & fCity) && (Database::realMap[loc1] >> 27) != static_cast<std::uint32_t>(p1)) ||
|
||||
|
||||
Reference in new issue
Block a user