initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,101 @@
|
||||
#include "Cevo/AiModuleHost.h"
|
||||
#include "Cevo/Geometry.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
bool AiModuleHost::handle(int command, int player, void *data)
|
||||
{
|
||||
switch (command) {
|
||||
case cmInitModule: {
|
||||
auto &init = *static_cast<TInitModuleData *>(data);
|
||||
CustomAI::setServerCall(init.Server);
|
||||
init.DataSize = m_rwDataSize;
|
||||
return true;
|
||||
}
|
||||
case cmNewGame:
|
||||
case cmLoadGame: {
|
||||
m_game = *static_cast<TNewGameData *>(data);
|
||||
InitGeometry(m_game);
|
||||
for (int p = nPl - 1; p >= 0; --p) {
|
||||
if (m_game.RO[p]) {
|
||||
m_ai[static_cast<size_t>(p)] = m_factory(p);
|
||||
m_ai[static_cast<size_t>(p)]->bind(m_game.RO[p]);
|
||||
m_ai[static_cast<size_t>(p)]->setDataDefaults();
|
||||
} else {
|
||||
m_ai[static_cast<size_t>(p)].reset();
|
||||
}
|
||||
}
|
||||
m_defender = -1;
|
||||
return true;
|
||||
}
|
||||
case cmGetReady:
|
||||
for (auto &a : m_ai)
|
||||
if (a)
|
||||
a->setDataRandom();
|
||||
return true;
|
||||
case cmBreakGame:
|
||||
for (auto &a : m_ai)
|
||||
a.reset();
|
||||
return true;
|
||||
case cmShowAttacking:
|
||||
case cmShowCapturing: {
|
||||
const auto &move = *static_cast<const TShowMove *>(data);
|
||||
const int y0 = move.FromLoc / m_game.lx;
|
||||
const int toLoc =
|
||||
(move.FromLoc + ((move.dx + (y0 & 1) + m_game.lx + m_game.lx) >> 1)) % m_game.lx +
|
||||
m_game.lx * (y0 + move.dy);
|
||||
if (player >= 0 && player < nPl && m_game.RO[player] && m_game.RO[player]->Map &&
|
||||
((*m_game.RO[player]->Map)[toLoc] & fOwned) != 0) {
|
||||
TUnitInfo unitInfo{};
|
||||
unitInfo.Loc = move.FromLoc;
|
||||
unitInfo.mix = static_cast<std::uint16_t>(move.mix);
|
||||
unitInfo.emix = static_cast<std::uint16_t>(move.emix);
|
||||
unitInfo.Owner = static_cast<std::uint8_t>(move.Owner);
|
||||
unitInfo.Health = static_cast<std::int8_t>(move.Health);
|
||||
unitInfo.Fuel = static_cast<std::int8_t>(move.Fuel);
|
||||
unitInfo.Job = jNone;
|
||||
unitInfo.Exp = static_cast<std::uint8_t>(move.Exp);
|
||||
unitInfo.Load = static_cast<std::uint8_t>(move.Load);
|
||||
unitInfo.Flags = static_cast<std::uint16_t>(move.Flags);
|
||||
if (m_ai[static_cast<size_t>(player)]) {
|
||||
if (command == cmShowAttacking)
|
||||
m_ai[static_cast<size_t>(player)]->onBeforeEnemyAttack(unitInfo, toLoc, move.EndHealth,
|
||||
move.EndHealthDef);
|
||||
else
|
||||
m_ai[static_cast<size_t>(player)]->onBeforeEnemyCapture(unitInfo, toLoc);
|
||||
}
|
||||
m_defender = player;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case cmShowAfterAttack:
|
||||
if (player == m_defender) {
|
||||
if (m_ai[static_cast<size_t>(player)])
|
||||
m_ai[static_cast<size_t>(player)]->onAfterEnemyAttack();
|
||||
m_defender = -1;
|
||||
}
|
||||
return true;
|
||||
case cmShowAfterMove:
|
||||
if (player == m_defender) {
|
||||
if (m_ai[static_cast<size_t>(player)])
|
||||
m_ai[static_cast<size_t>(player)]->onAfterEnemyCapture();
|
||||
m_defender = -1;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (player < 0 || player >= nPl || !m_ai[static_cast<size_t>(player)])
|
||||
return false;
|
||||
|
||||
if (command == cmTurn || command == cmContinue || command == cmShowNego || command == cmShowEndContact ||
|
||||
(command >= scContact && command <= scDipBreak)) {
|
||||
m_ai[static_cast<size_t>(player)]->process(command, data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
|
||||
Reference in new issue
Block a user