Skip to content

Commit

Permalink
Recloned epicinium/ from Aftermath. Version 1.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
SLiV9 committed Jul 12, 2021
1 parent cc77ae6 commit 4c7336f
Show file tree
Hide file tree
Showing 26 changed files with 463 additions and 76 deletions.
10 changes: 10 additions & 0 deletions epicinium/src/ai/ai.cpp
Expand Up @@ -131,3 +131,13 @@ const std::vector<std::string>& AI::hiddenPool()
};
return pool;
}

const std::vector<std::string>& AI::selfHostedPool()
{
static std::vector<std::string> pool = {
"RampantRhino",
"HungryHippo",
"ChargingCheetah",
};
return pool;
}
1 change: 1 addition & 0 deletions epicinium/src/ai/ai.hpp
Expand Up @@ -45,6 +45,7 @@ class AI
static std::string libraryDefaultFilename(const std::string& name);

static const std::vector<std::string>& pool();
static const std::vector<std::string>& selfHostedPool();

private:
static const std::vector<std::string>& hiddenPool();
Expand Down
23 changes: 8 additions & 15 deletions epicinium/src/ai/aichallenge.cpp
Expand Up @@ -37,21 +37,14 @@ const char* AIChallenge::getKey(const Challenge::Id& id)
switch (id)
{
case CUSTOM: return "";
// OLD: "showcase_2018_07_04";
// OLD: "elimination_2017_07_20";
// OLD: "everythingisfree_2018_07_16";
// OLD: "trample_2017_08_01";
// OLD: "trample_2018_11_26";
// OLD: "highspeed_2018_09_21";
// OLD: "investment_2019_04_15";
// OLD: "morale_2020_05_06";
case SHOWCASE: return "showcase_2021_05_25";
case ELIMINATION: return "elimination_2021_05_25";
case EVERYTHINGISFREE: return "everythingisfree_2021_05_25";
case TRAMPLE: return "trample_2021_05_25";
case HIGHSPEED: return "highspeed_2021_05_25";
case INVESTMENT: return "investment_2021_05_25";
case MORALE: return "morale_2021_05_25";
case SHOWCASE: return "showcase_2018_07_04";
case ELIMINATION: return "elimination_2017_07_20";
case EVERYTHINGISFREE: return "everythingisfree_2018_07_16";
case TRAMPLE: return "trample_2018_11_26";
case HIGHSPEED: return "highspeed_2018_09_21";
case INVESTMENT: return "investment_2019_04_15";
case MORALE: return "morale_2020_05_06";
}
return "";
}
Expand Down Expand Up @@ -165,7 +158,7 @@ const char* AIChallenge::getRulesetName(const Challenge::Id& id)
{
switch (id)
{
case CUSTOM: return "";
case CUSTOM: return "challenge_custom";
case SHOWCASE: return "";
case ELIMINATION: return "";
case EVERYTHINGISFREE: return "challenge_everythingisfree";
Expand Down
8 changes: 7 additions & 1 deletion epicinium/src/ai/aineuralnewt.cpp
Expand Up @@ -28,6 +28,9 @@
#include "aim.hpp"
#include "bible.hpp"

// windows.h is being annoying
#undef near


std::string AINeuralNewt::ainame() const
{
Expand Down Expand Up @@ -937,7 +940,10 @@ void AINeuralNewt::moveDefense(const Descriptor& unitdesc,
for (Cell at : _board)
{
if (_board.gas(at)) continue;
if (_board.frostbite(at)) continue;
if (_board.frostbite(at)
// In Spring, frostbite is used to indicate "Chilled" units.
&& !(_bible.frostbiteGivesColdFeet()
&& _bible.chaosMinFrostbite(_season) < 0)) continue;
if (_board.firestorm(at)) continue;
if (_board.death(at)) continue;
int threatdis = _enemyBaseFloodfill.steps(at);
Expand Down
50 changes: 46 additions & 4 deletions epicinium/src/ai/airampantrhino.cpp
Expand Up @@ -29,6 +29,9 @@
#include "aim.hpp"
#include "bible.hpp"

// windows.h is being annoying
#undef near


std::string AIRampantRhino::ainame() const
{
Expand Down Expand Up @@ -1530,6 +1533,14 @@ bool AIRampantRhino::checkLockdown(const Descriptor& unitdesc)
{
Cell at = _board.cell(unitdesc.position);

bool canUseAbilities = true;
if (_bible.frostbiteGivesColdFeet()
// In Spring, frostbite is used to indicate "Chilled" units.
&& _board.frostbite(at) && _bible.chaosMinFrostbite(_season) < 0)
{
canUseAbilities = false;
}

std::vector<Move> dirs = {Move::E, Move::S, Move::W, Move::N};
std::random_shuffle(dirs.begin(), dirs.end());
for (const Move& move : dirs)
Expand All @@ -1540,7 +1551,7 @@ bool AIRampantRhino::checkLockdown(const Descriptor& unitdesc)
if (_board.ground(target)
&& _board.ground(target).owner != _player)
{
if (canUseCombatAbilities())
if (canUseAbilities && canUseCombatAbilities())
{
UnitType unittype = _board.ground(at).type;
std::vector<Bible::TileBuild> shapes = _bible.unitShapes(
Expand All @@ -1567,6 +1578,7 @@ bool AIRampantRhino::checkLockdown(const Descriptor& unitdesc)
Descriptor::cell(target.pos()));
}
}

return true;
}
}
Expand All @@ -1588,6 +1600,13 @@ void AIRampantRhino::controlIdleDefense(const Descriptor& unitdesc)

Cell at = _board.cell(unitdesc.position);

if (_bible.frostbiteGivesColdFeet()
// In Spring, frostbite is used to indicate "Chilled" units.
&& _board.frostbite(at) && _bible.chaosMinFrostbite(_season) < 0)
{
return;
}

std::vector<Move> dirs = {Move::E, Move::S, Move::W, Move::N};
std::random_shuffle(dirs.begin(), dirs.end());
for (const Move& move : dirs)
Expand All @@ -1613,6 +1632,13 @@ void AIRampantRhino::controlCaptor(const Descriptor& unitdesc)
{
Cell at = _board.cell(unitdesc.position);

if (_bible.frostbiteGivesColdFeet()
// In Spring, frostbite is used to indicate "Chilled" units.
&& _board.frostbite(at) && _bible.chaosMinFrostbite(_season) < 0)
{
return;
}

if (_board.tile(at)
&& _board.tile(at).owner != _player
&& _bible.tileOwnable(_board.tile(at).type))
Expand Down Expand Up @@ -1643,7 +1669,10 @@ void AIRampantRhino::controlBlocker(const Descriptor& unitdesc)
if (at == from) continue;
if (_board.ground(at)) continue;
if (_board.gas(at)) continue;
if (_board.frostbite(at)) continue;
if (_board.frostbite(at)
// In Spring, frostbite is used to indicate "Chilled" units.
&& !(_bible.frostbiteGivesColdFeet()
&& _bible.chaosMinFrostbite(_season) < 0)) continue;
if (_board.firestorm(at)) continue;
if (_board.death(at)) continue;
if (isTarget(at.pos())) continue;
Expand Down Expand Up @@ -1758,7 +1787,10 @@ void AIRampantRhino::controlDefense(const Descriptor& unitdesc)
if (at != from && _board.ground(at)
&& _board.ground(at).owner == _player) continue;
if (_board.gas(at)) continue;
if (_board.frostbite(at)) continue;
if (_board.frostbite(at)
// In Spring, frostbite is used to indicate "Chilled" units.
&& !(_bible.frostbiteGivesColdFeet()
&& _bible.chaosMinFrostbite(_season) < 0)) continue;
if (_board.firestorm(at)) continue;
if (_board.death(at)) continue;
if (isTarget(at.pos())) continue;
Expand Down Expand Up @@ -1911,7 +1943,10 @@ void AIRampantRhino::declareOffense(const Descriptor& unitdesc)
if (at != from && _board.ground(at)
&& _board.ground(at).owner == _player) continue;
if (_board.gas(at)) continue;
if (_board.frostbite(at)) continue;
if (_board.frostbite(at)
// In Spring, frostbite is used to indicate "Chilled" units.
&& !(_bible.frostbiteGivesColdFeet()
&& _bible.chaosMinFrostbite(_season) < 0)) continue;
if (_board.firestorm(at)) continue;
if (_board.death(at)) continue;
if (isTarget(at.pos())) continue;
Expand Down Expand Up @@ -2055,6 +2090,13 @@ void AIRampantRhino::controlBombarder(const Descriptor& unitdesc)
Cell from = _board.cell(unitdesc.position);
const UnitToken& unit = _board.ground(from);

if (_bible.frostbiteGivesColdFeet()
// In Spring, frostbite is used to indicate "Chilled" units.
&& _board.frostbite(from) && _bible.chaosMinFrostbite(_season) < 0)
{
return;
}

UnitType unittype = unit.type;
int rangeMin = _bible.unitRangeMin(unittype);
int rangeMax = _bible.unitRangeMax(unittype);
Expand Down
4 changes: 4 additions & 0 deletions epicinium/src/common/header.hpp
Expand Up @@ -149,3 +149,7 @@ struct stringref;
#ifndef EDITOR_DEPRECATED_ENABLED
#define EDITOR_DEPRECATED_ENABLED false
#endif

#ifndef NEURALNEWT_20x13_ENABLED
#define NEURALNEWT_20x13_ENABLED false
#endif
100 changes: 100 additions & 0 deletions epicinium/src/common/locator.cpp
Expand Up @@ -30,6 +30,7 @@
std::string Locator::_resourceroot = "";
std::string Locator::_cacheroot = "";
std::string Locator::_authoredroot = "";
std::vector<Locator::ExternalFolder> Locator::_externalfolders = {};

void Locator::setResourceRoot(const std::string& root)
{
Expand Down Expand Up @@ -119,6 +120,36 @@ std::string Locator::picture(const std::string& picturename)

std::string Locator::pictureFilename(const std::string& picturename)
{
if (picturename.find_first_of('@') != std::string::npos)
{
size_t seppos = picturename.find_first_of('/');
std::string shortname;
// Use x.rfind(y, 0) == 0 as x.starts_with(y).
if (picturename.rfind("panels/", 0) == 0)
{
shortname = "panel";
}

if (!shortname.empty() && seppos != std::string::npos)
{
std::string tag = picturename.substr(seppos + 1);
for (const auto& folder : _externalfolders)
{
if (folder.uniqueTag == tag)
{
return folder.sourcePath + shortname + ".png";
}
}
LOGW << "Failed to find external tag '" << tag << "'"
" for picture '" << picturename << "'";
}
else
{
LOGW << "Failed to determine shortname"
" for picture '" << picturename << "'";
}
}

return _cacheroot + "pictures/" + picturename + ".png";
}

Expand All @@ -137,6 +168,20 @@ std::string Locator::pictureName(const std::string& fullfilename)

std::string Locator::rulesetFilename(const std::string& rulesetname)
{
if (rulesetname.find_first_of('@') != std::string::npos)
{
std::string tag = rulesetname;
for (const auto& folder : _externalfolders)
{
if (folder.uniqueTag == tag)
{
return folder.sourcePath + "ruleset.json";
}
}
size_t seppos = rulesetname.find_first_of('@');
std::string subpath = rulesetname.substr(seppos + 1);
return _cacheroot + "rulesets/external/" + subpath + ".json";
}
return _cacheroot + "rulesets/" + rulesetname + ".json";
}

Expand Down Expand Up @@ -180,3 +225,58 @@ std::string Locator::fzmodelName(const std::string& fullfilename)
}
return "";
}

void Locator::useExternalFolder(ExternalFolder&& newFolder)
{
LOGD << "Using '" << newFolder.uniqueTag << "'"
": " << newFolder.sourcePath;

for (auto& folder : _externalfolders)
{
if (folder.uniqueTag == newFolder.uniqueTag)
{
folder = newFolder;
return;
}
}

_externalfolders.emplace_back(newFolder);
}

void Locator::forgetExternalFolder(const std::string& uniqueTag)
{
LOGD << "Forgetting '" << uniqueTag << "'";
_externalfolders.erase(
std::remove_if(
_externalfolders.begin(),
_externalfolders.end(),
[&](const ExternalFolder& folder) {
return folder.uniqueTag == uniqueTag;
}),
_externalfolders.end());
}

std::vector<std::string> Locator::externalRulesets()
{
std::vector<std::string> rulesets;
for (const auto& folder : _externalfolders)
{
if (System::isFile(folder.sourcePath + "ruleset.json"))
{
rulesets.emplace_back(folder.uniqueTag);
}
}
return rulesets;
}

const std::vector<Locator::ExternalFolder>& Locator::externalFolders()
{
return _externalfolders;
}

std::vector<std::string> Locator::listAuthoredRulesets()
{
auto list = System::listDirectory(_authoredroot + "rulesets/", ".json");
std::sort(list.begin(), list.end());
return list;
}
15 changes: 15 additions & 0 deletions epicinium/src/common/locator.hpp
Expand Up @@ -28,6 +28,12 @@
class Locator
{
public:
struct ExternalFolder
{
std::string uniqueTag;
std::string sourcePath;
};

static std::string picture(const std::string& picturename);

static std::string pictureFilename(const std::string& picturename);
Expand All @@ -45,9 +51,18 @@ class Locator
static std::string _resourceroot;
static std::string _cacheroot;
static std::string _authoredroot;
static std::vector<ExternalFolder> _externalfolders;

public:
static void setResourceRoot(const std::string& root);
static void setCacheRoot(const std::string& root);
static void setAuthoredRoot(const std::string& root);

static void useExternalFolder(ExternalFolder&& folder);
static void forgetExternalFolder(const std::string& uniqueTag);

static std::vector<std::string> externalRulesets();
static const std::vector<ExternalFolder>& externalFolders();

static std::vector<std::string> listAuthoredRulesets();
};
4 changes: 4 additions & 0 deletions epicinium/src/common/system.cpp
Expand Up @@ -52,6 +52,10 @@ std::vector<std::string> System::listDirectory(const std::string& dirname,
}

std::vector<std::string> filenames;
if (!System::isDirectory(dirname))
{
return filenames;
}
for(const auto& p : fs::directory_iterator(dirname))
{
if (p.path().extension() == extensionPattern)
Expand Down
4 changes: 2 additions & 2 deletions epicinium/src/common/writer.cpp
Expand Up @@ -34,7 +34,7 @@


static std::map<std::thread::id, Writer*> _installed;
static std::mutex _mutex;
static std::mutex _writerMutex;

std::string Writer::write(const Json::Value& json)
{
Expand Down Expand Up @@ -62,7 +62,7 @@ Writer::Writer()

void Writer::install()
{
std::lock_guard<std::mutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_writerMutex);
_installed[std::this_thread::get_id()] = this;
}

Expand Down

0 comments on commit 4c7336f

Please sign in to comment.