Skip to content

Commit

Permalink
Add base function buy requiremnts
Browse files Browse the repository at this point in the history
  • Loading branch information
Yankes committed Aug 5, 2018
1 parent cfd7fb9 commit 198ef2f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 4 deletions.
14 changes: 13 additions & 1 deletion Extended.txt
Expand Up @@ -183,6 +183,7 @@ Update nightly.[br/]
4.0:[br/]
Damage script can now alter zombie transformation chance.[br/]
Add access to current difficulty level in scripts.[br/]
Add base function requirmets to buy items, crafts and solders.[br/]
[br/]

[examples]
Expand Down Expand Up @@ -445,6 +446,8 @@ items:
requiresBuy: #what tech is required for the item to be visible in the Hire/Purchase screen.
- SOME_TECH
- SOME_TECH_MK2
requiresBuyBaseFunc: #list of required base functions needed to buy this.
- SOME_BASE_FUNC_A
psiAttackName: STR_HIT_MELEE #string id of psi-amp attack name in the pop-up menu. Required to enable special attack.
primeActionName: STR_PRIME_GRENADE #string id of grenade prime action name in the pop-up menu. Required to enable prime action. Defulat value `STR_PRIME_GRENADE`;
primeActionMessage: STR_GRENADE_IS_ACTIVATED #string id of grenade prime action message.
Expand Down Expand Up @@ -549,9 +552,18 @@ armors:
newTurnUnit: ~ #script call on every turn for every unit in battlescape.
[/code]

[code]
soldiers:
- type: STR_SOLDIER_A
requiresBuyBaseFunc: #list of required base functions needed to buy this.
- SOME_BASE_FUNC_A
[/code]

[code]
crafts:
- type: STR_CRAFT_TYPE #default config ...
- type: STR_CRAFT_TYPE #default config ...
requiresBuyBaseFunc: #list of required base functions needed to buy this.
- SOME_BASE_FUNC_A
radarRange: 672 #craft radar range. Default `672`.
radarChance: 100 #craft radar dedection chance. Default `100`.
sightRange: 1696 #alien base dedection range. Default `1696`.
Expand Down
10 changes: 7 additions & 3 deletions src/Basescape/PurchaseState.cpp
Expand Up @@ -146,11 +146,13 @@ PurchaseState::PurchaseState(Base *base) : _base(base), _sel(0), _total(0), _pQt
_armors.insert(rule->getStoreItem());
}

const std::vector<std::string> &providedBaseFunc = _base->getProvidedBaseFunc();
const std::vector<std::string> &soldiers = _game->getMod()->getSoldiersList();
for (std::vector<std::string>::const_iterator i = soldiers.begin(); i != soldiers.end(); ++i)
{
RuleSoldier *rule = _game->getMod()->getSoldier(*i);
if (rule->getBuyCost() != 0 && _game->getSavedGame()->isResearched(rule->getRequirements()))
const std::vector<std::string> &purchaseBaseFunc = rule->getRequiresBuyBaseFunc();
if (rule->getBuyCost() != 0 && _game->getSavedGame()->isResearched(rule->getRequirements()) && std::includes(providedBaseFunc.begin(), providedBaseFunc.end(), purchaseBaseFunc.begin(), purchaseBaseFunc.end()))
{
TransferRow row = { TRANSFER_SOLDIER, rule, tr(rule->getType()), rule->getBuyCost(), _base->getSoldierCount(rule->getType()), 0, 0 };
_items.push_back(row);
Expand Down Expand Up @@ -183,7 +185,8 @@ PurchaseState::PurchaseState(Base *base) : _base(base), _sel(0), _total(0), _pQt
for (std::vector<std::string>::const_iterator i = crafts.begin(); i != crafts.end(); ++i)
{
RuleCraft *rule = _game->getMod()->getCraft(*i);
if (rule->getBuyCost() != 0 && _game->getSavedGame()->isResearched(rule->getRequirements()))
const std::vector<std::string> &purchaseBaseFunc = rule->getRequiresBuyBaseFunc();
if (rule->getBuyCost() != 0 && _game->getSavedGame()->isResearched(rule->getRequirements()) && std::includes(providedBaseFunc.begin(), providedBaseFunc.end(), purchaseBaseFunc.begin(), purchaseBaseFunc.end()))
{
TransferRow row = { TRANSFER_CRAFT, rule, tr(rule->getType()), rule->getBuyCost(), _base->getCraftCount(rule), 0, 0 };
_items.push_back(row);
Expand All @@ -198,7 +201,8 @@ PurchaseState::PurchaseState(Base *base) : _base(base), _sel(0), _total(0), _pQt
for (std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i)
{
RuleItem *rule = _game->getMod()->getItem(*i);
if (rule->getBuyCost() != 0 && _game->getSavedGame()->isResearched(rule->getRequirements()) && _game->getSavedGame()->isResearched(rule->getBuyRequirements()))
const std::vector<std::string> &purchaseBaseFunc = rule->getRequiresBuyBaseFunc();
if (rule->getBuyCost() != 0 && _game->getSavedGame()->isResearched(rule->getRequirements()) && _game->getSavedGame()->isResearched(rule->getBuyRequirements()) && std::includes(providedBaseFunc.begin(), providedBaseFunc.end(), purchaseBaseFunc.begin(), purchaseBaseFunc.end()))
{
TransferRow row = { TRANSFER_ITEM, rule, tr(rule->getType()), rule->getBuyCost(), _base->getStorageItems()->getItem(rule->getType()), 0, 0 };
_items.push_back(row);
Expand Down
17 changes: 17 additions & 0 deletions src/Mod/RuleCraft.cpp
Expand Up @@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "RuleCraft.h"
#include "RuleTerrain.h"
#include "../Engine/Exception.h"
Expand Down Expand Up @@ -69,7 +70,14 @@ void RuleCraft::load(const YAML::Node &node, Mod *mod, int listOrder)
load(parent, mod, listOrder);
}
_type = node["type"].as<std::string>(_type);

//requires
_requires = node["requires"].as< std::vector<std::string> >(_requires);
_requiresBuyBaseFunc = node["requiresBuyBaseFunc"].as< std::vector<std::string> >(_requiresBuyBaseFunc);

std::sort(_requiresBuyBaseFunc.begin(), _requiresBuyBaseFunc.end());


if (node["sprite"])
{
_sprite = node["sprite"].as<int>(_sprite);
Expand Down Expand Up @@ -156,6 +164,15 @@ const std::vector<std::string> &RuleCraft::getRequirements() const
return _requires;
}

/**
* Gets the base functions required to buy craft.
* @retreturn The sorted list of base functions ID
*/
const std::vector<std::string> &RuleCraft::getRequiresBuyBaseFunc() const
{
return _requiresBuyBaseFunc;
}

/**
* Gets the ID of the sprite used to draw the craft
* in the Basescape and Equip Craft screens.
Expand Down
5 changes: 5 additions & 0 deletions src/Mod/RuleCraft.h
Expand Up @@ -115,6 +115,7 @@ class RuleCraft
private:
std::string _type;
std::vector<std::string> _requires;
std::vector<std::string> _requiresBuyBaseFunc;
int _sprite, _marker;
int _weapons, _soldiers, _vehicles, _costBuy, _costRent, _costSell;
char _weaponTypes[WeaponMax][WeaponTypeMax];
Expand All @@ -137,6 +138,8 @@ class RuleCraft
const std::string &getType() const;
/// Gets the craft's requirements.
const std::vector<std::string> &getRequirements() const;
/// Gets the base functions required to buy craft.
const std::vector<std::string> &getRequiresBuyBaseFunc() const;
/// Gets the craft's sprite.
int getSprite() const;
/// Gets the craft's globe marker.
Expand All @@ -161,6 +164,8 @@ class RuleCraft
int getRentCost() const;
/// Gets the craft's value.
int getSellCost() const;
/// Gets craft type.
int getCraftType() const;
/// Gets the craft's refuel item.
const std::string &getRefuelItem() const;
/// Gets the craft's repair rate.
Expand Down
16 changes: 16 additions & 0 deletions src/Mod/RuleItem.cpp
Expand Up @@ -284,8 +284,15 @@ void RuleItem::load(const YAML::Node &node, Mod *mod, int listOrder, const ModSc
_type = node["type"].as<std::string>(_type);
_name = node["name"].as<std::string>(_name);
_nameAsAmmo = node["nameAsAmmo"].as<std::string>(_nameAsAmmo);

//requires
_requiresName = node["requires"].as< std::vector<std::string> >(_requiresName);
_requiresBuyName = node["requiresBuy"].as< std::vector<std::string> >(_requiresBuyName);
_requiresBuyBaseFunc = node["requiresBuyBaseFunc"].as< std::vector<std::string> >(_requiresBuyBaseFunc);

std::sort(_requiresBuyBaseFunc.begin(), _requiresBuyBaseFunc.end());


_categories = node["categories"].as< std::vector<std::string> >(_categories);
_size = node["size"].as<double>(_size);
_costBuy = node["costBuy"].as<int>(_costBuy);
Expand Down Expand Up @@ -670,6 +677,15 @@ const std::vector<const RuleResearch *> &RuleItem::getBuyRequirements() const
return _requiresBuy;
}

/**
* Gets the base functions required to buy item.
* @retreturn The sorted list of base functions ID
*/
const std::vector<std::string> &RuleItem::getRequiresBuyBaseFunc() const
{
return _requiresBuyBaseFunc;
}

/**
* Gets the list of categories
* this item belongs to.
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/RuleItem.h
Expand Up @@ -132,6 +132,7 @@ class RuleItem
std::vector<std::string> _requiresBuyName;
std::vector<std::string> _categories;
std::vector<const RuleResearch *> _requires, _requiresBuy;
std::vector<std::string> _requiresBuyBaseFunc;
double _size;
int _costBuy, _costSell, _transferTime, _weight;
int _bigSprite;
Expand Down Expand Up @@ -223,6 +224,8 @@ class RuleItem
const std::vector<const RuleResearch*> &getRequirements() const;
/// Gets the item's buy requirements.
const std::vector<const RuleResearch*> &getBuyRequirements() const;
/// Gets the base functions required to buy craft.
const std::vector<std::string> &getRequiresBuyBaseFunc() const;
/// Gets the item's categories.
const std::vector<std::string> &getCategories() const;
/// Checks if the item belongs to a category.
Expand Down
17 changes: 17 additions & 0 deletions src/Mod/RuleSoldier.cpp
Expand Up @@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include "RuleSoldier.h"
#include "Mod.h"
#include "SoldierNamePool.h"
Expand Down Expand Up @@ -59,7 +60,14 @@ void RuleSoldier::load(const YAML::Node &node, Mod *mod)
// Just in case
if (_type == "XCOM")
_type = "STR_SOLDIER";

//requires
_requires = node["requires"].as< std::vector<std::string> >(_requires);
_requiresBuyBaseFunc = node["requiresBuyBaseFunc"].as< std::vector<std::string> >(_requiresBuyBaseFunc);

std::sort(_requiresBuyBaseFunc.begin(), _requiresBuyBaseFunc.end());


_minStats.merge(node["minStats"].as<UnitStats>(_minStats));
_maxStats.merge(node["maxStats"].as<UnitStats>(_maxStats));
_statCaps.merge(node["statCaps"].as<UnitStats>(_statCaps));
Expand Down Expand Up @@ -160,6 +168,15 @@ const std::vector<std::string> &RuleSoldier::getRequirements() const
return _requires;
}

/**
* Gets the base functions required to buy solder.
* @retreturn The sorted list of base functions ID
*/
const std::vector<std::string> &RuleSoldier::getRequiresBuyBaseFunc() const
{
return _requiresBuyBaseFunc;
}

/**
* Gets the minimum stats for the random stats generator.
* @return The minimum stats.
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/RuleSoldier.h
Expand Up @@ -37,6 +37,7 @@ class RuleSoldier
private:
std::string _type;
std::vector<std::string> _requires;
std::vector<std::string> _requiresBuyBaseFunc;
UnitStats _minStats, _maxStats, _statCaps;
std::string _armor;
int _costBuy, _costSalary, _standHeight, _kneelHeight, _floatHeight, _femaleFrequency;
Expand All @@ -55,6 +56,8 @@ class RuleSoldier
std::string getType() const;
/// Gets the soldier's requirements.
const std::vector<std::string> &getRequirements() const;
/// Gets the base functions required to buy solder.
const std::vector<std::string> &getRequiresBuyBaseFunc() const;
/// Gets the minimum stats for the random stats generator.
UnitStats getMinStats() const;
/// Gets the maximum stats for the random stats generator.
Expand Down

0 comments on commit 198ef2f

Please sign in to comment.