Skip to content

Commit

Permalink
Mapscript commands filter by craft (group)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeridianOXC committed Jan 14, 2024
1 parent fe4f8cf commit d724b3f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Battlescape/BattlescapeGenerator.cpp
Expand Up @@ -2676,6 +2676,28 @@ void BattlescapeGenerator::generateMap(const std::vector<MapScript*> *script, co
}
}

// if this command runs conditionally based on deployed craft's groups
if (_craftDeployed && _craftRules)
{
if (!command->getCraftGroups().empty())
{
bool execute = false;
// compare the corresponding entries in the craft rules vector
for (int grp : command->getCraftGroups())
{
if (std::find(_craftRules->getGroups().begin(), _craftRules->getGroups().end(), grp) != _craftRules->getGroups().end())
{
execute = true;
break;
}
}
if (!execute)
{
continue;
}
}
}

// if there's a chance a command won't execute by design, take that into account here.
if (RNG::percent(command->getChancesOfExecution()))
{
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/MapScript.cpp
Expand Up @@ -106,6 +106,10 @@ void MapScript::load(const YAML::Node& node)
_rects.push_back(rect);
}
}
if (const YAML::Node& craftGroups = node["craftGroups"])
{
_craftGroups = craftGroups.as<std::vector<int> >(_craftGroups);
}
if (const YAML::Node &map = node["tunnelData"])
{
_tunnelData = new TunnelData;
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/MapScript.h
Expand Up @@ -173,6 +173,7 @@ class MapScript
MapScriptCommand _type;
bool _canBeSkipped, _markAsReinforcementsBlock;
std::vector<SDL_Rect*> _rects;
std::vector<int> _craftGroups;
std::vector<int> _groups, _blocks, _frequencies, _maxUses, _conditionals;
int _verticalGroup, _horizontalGroup, _crossingGroup;
std::vector<int> _groupsTemp, _blocksTemp, _frequenciesTemp, _maxUsesTemp;
Expand Down Expand Up @@ -204,6 +205,8 @@ class MapScript
bool markAsReinforcementsBlock() const { return _markAsReinforcementsBlock; }
/// Gets the rects, describing the areas this command applies to.
const std::vector<SDL_Rect*> *getRects() const {return &_rects;};
/// Gets the craft groups vector for iteration.
const std::vector<int>& getCraftGroups() const { return _craftGroups; };
/// Gets the X size for this command.
int getSizeX() const {return _sizeX;};
/// Gets the Y size for this command.
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/RuleCraft.cpp
Expand Up @@ -141,6 +141,10 @@ void RuleCraft::load(const YAML::Node &node, Mod *mod, const ModScript &parsers)
{
_craftInventoryTile = craftInventoryTile.as<std::vector<int> >(_craftInventoryTile);
}
if (const YAML::Node& craftGroups = node["groups"])
{
_groups = craftGroups.as<std::vector<int> >(_groups);
}
_maxSkinIndex = node["maxSkinIndex"].as<int>(_maxSkinIndex);
_deployment = node["deployment"].as< RuleCraftDeployment >(_deployment);
_keepCraftAfterFailedMission = node["keepCraftAfterFailedMission"].as<bool>(_keepCraftAfterFailedMission);
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/RuleCraft.h
Expand Up @@ -209,6 +209,7 @@ class RuleCraft
std::string _defaultAltitude;
RuleCraftDeployment _deployment;
std::vector<int> _craftInventoryTile;
std::vector<int> _groups;
RuleCraftStats _stats;
int _shieldRechargeAtBase;
bool _mapVisible, _forceShowInMonthlyCosts;
Expand Down Expand Up @@ -330,6 +331,8 @@ class RuleCraft
const RuleCraftDeployment &getDeployment() const;
/// Gets the craft inventory tile position.
const std::vector<int> &getCraftInventoryTile() const;
/// Gets the craft groups (used in map scripts).
const std::vector<int>& getGroups() const { return _groups; }
/// Gets the item limit for this craft.
int getMaxItems() const;
/// Gets the item storage space limit for this craft.
Expand Down
1 change: 1 addition & 0 deletions src/Ufopaedia/StatsForNerdsState.cpp
Expand Up @@ -3400,6 +3400,7 @@ void StatsForNerdsState::initCraftList()
addBoolean(ss, craftRule->getBattlescapeTerrainData() != 0, "battlescapeTerrainData", false); // just say if there is any or not
addBoolean(ss, craftRule->isMapVisible(), "mapVisible", true);
addVectorOfIntegers(ss, craftRule->getCraftInventoryTile(), "craftInventoryTile");
addVectorOfIntegers(ss, craftRule->getGroups(), "groups");
addBoolean(ss, craftRule->useAllStartTiles(), "useAllStartTiles");
addSingleString(ss, craftRule->getCustomPreviewTypeRaw(), "customPreview");
if (craftRule->getDeployment().empty())
Expand Down

0 comments on commit d724b3f

Please sign in to comment.