Skip to content

Commit

Permalink
Convert default/scripting/techs/ship_parts/fuel/SHP_ANTIMATTER_TANK.focs
Browse files Browse the repository at this point in the history
  • Loading branch information
o01eg committed Jul 30, 2022
1 parent dfc2d2c commit 7e2ef94
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 20 deletions.
@@ -0,0 +1,15 @@
from common.base_prod import TECH_COST_MULTIPLIER
from techs.ship_parts.fuel.fuel import PART_UPGRADE_MAXFUEL_EFFECTS

Tech(
name="SHP_ANTIMATTER_TANK",
description="SHP_ANTIMATTER_TANK_DESC",
short_description="SHIP_FUEL_IMPROVE_SHORT_DESC",
category="SHIP_PARTS_CATEGORY",
researchcost=175 * TECH_COST_MULTIPLIER,
researchturns=3,
tags=["PEDIA_FUEL_PART_TECHS"],
prerequisites=["SHP_DEUTERIUM_TANK", "LRN_FORCE_FIELD"],
effectsgroups=[PART_UPGRADE_MAXFUEL_EFFECTS("SHP_ANTIMATTER_TANK_EFFECT", 1.5)],
graphic="icons/ship_parts/antimatter_tank.png",
)

This file was deleted.

16 changes: 16 additions & 0 deletions default/scripting/techs/ship_parts/fuel/fuel.py
@@ -0,0 +1,16 @@
# Increase the fuel capacity of ships with FU_BASIC_TANK parts.
# Adds the given increase amount times the number of FU_BASIC_TANK parts in the design to the max fuel meter.
# @1@ Accounting label to present this effect with
# @2@ Fuel capacity increase per fuel part
def PART_UPGRADE_MAXFUEL_EFFECTS(effect_name: str, value: float):
return EffectsGroup(
scope=Ship & OwnedBy(empire=Source.Owner) & DesignHasPart(name="FU_BASIC_TANK"),
accountinglabel=effect_name,
effects=[
SetMaxFuel(
value=Value
+ NamedReal(name=effect_name + "_MULT", value=value)
* PartsInShipDesign(name="FU_BASIC_TANK", design=Target.DesignID)
)
],
)
2 changes: 2 additions & 0 deletions default/scripting/tox.ini
Expand Up @@ -19,6 +19,7 @@ builtins =
ContainedBy
Contains
CurrentTurn
DesignHasPart
Destroy
DirectDistanceBetween
EffectsGroup
Expand Down Expand Up @@ -54,6 +55,7 @@ builtins =
Orange
OwnedBy
OwnerHasTech
PartsInShipDesign
Planet
Poor
Population
Expand Down
36 changes: 36 additions & 0 deletions parse/ConditionPythonParser.cpp
Expand Up @@ -284,6 +284,41 @@ namespace {
return condition_wrapper(std::make_shared<Condition::FleetSupplyableByEmpire>(std::move(empire)));
}

condition_wrapper insert_design_has_part_(const boost::python::tuple& args, const boost::python::dict& kw) {
std::unique_ptr<ValueRef::ValueRef<std::string>> name;
auto name_args = boost::python::extract<value_ref_wrapper<std::string>>(kw["name"]);
if (name_args.check()) {
name = ValueRef::CloneUnique(name_args().value_ref);
} else {
name = std::make_unique<ValueRef::Constant<std::string>>(boost::python::extract<std::string>(kw["name"])());
}

std::unique_ptr<ValueRef::ValueRef<int>> low;
if (kw.has_key("low")) {
auto low_args = boost::python::extract<value_ref_wrapper<int>>(kw["low"]);
if (low_args.check()) {
low = ValueRef::CloneUnique(low_args().value_ref);
} else {
low = std::make_unique<ValueRef::Constant<int>>(boost::python::extract<int>(kw["low"])());
}
}

std::unique_ptr<ValueRef::ValueRef<int>> high;
if (kw.has_key("high")) {
auto high_args = boost::python::extract<value_ref_wrapper<int>>(kw["high"]);
if (high_args.check()) {
high = ValueRef::CloneUnique(high_args().value_ref);
} else {
high = std::make_unique<ValueRef::Constant<int>>(boost::python::extract<int>(kw["high"])());
}
}

return condition_wrapper(std::make_shared<Condition::DesignHasPart>(
std::move(name),
std::move(low),
std::move(high)));
}

condition_wrapper insert_owner_has_tech_(const boost::python::tuple& args, const boost::python::dict& kw) {
std::unique_ptr<ValueRef::ValueRef<std::string>> name;
auto name_args = boost::python::extract<value_ref_wrapper<std::string>>(kw["name"]);
Expand Down Expand Up @@ -377,6 +412,7 @@ void RegisterGlobalsConditions(boost::python::dict& globals) {
globals["Star"] = boost::python::raw_function(insert_star_);
globals["InSystem"] = boost::python::raw_function(insert_in_system_);
globals["ResupplyableBy"] = boost::python::raw_function(insert_resupplyable_by_);
globals["DesignHasPart"] = boost::python::raw_function(insert_design_has_part_);

// non_ship_part_meter_enum_grammar
for (const auto& meter : std::initializer_list<std::pair<const char*, MeterType>>{
Expand Down
1 change: 1 addition & 0 deletions parse/PythonParser.cpp
Expand Up @@ -96,6 +96,7 @@ PythonParser::PythonParser(PythonCommon& _python, const boost::filesystem::path&
.def("__call__", &value_ref_wrapper<double>::call)
.def(int() * py::self_ns::self)
.def(py::other<value_ref_wrapper<int>>() * py::self_ns::self)
.def(py::self_ns::self * py::other<value_ref_wrapper<int>>())
.def(py::self_ns::self * double())
.def(py::self_ns::self * py::self_ns::self)
.def(double() * py::self_ns::self)
Expand Down
39 changes: 39 additions & 0 deletions parse/ValueRefPythonParser.cpp
Expand Up @@ -40,6 +40,15 @@ value_ref_wrapper<double> operator*(const value_ref_wrapper<int>& lhs, const val
);
}

value_ref_wrapper<double> operator*(const value_ref_wrapper<double>& lhs, const value_ref_wrapper<int>& rhs) {
return value_ref_wrapper<double>(
std::make_shared<ValueRef::Operation<double>>(ValueRef::OpType::TIMES,
ValueRef::CloneUnique(lhs.value_ref),
std::make_unique<ValueRef::StaticCast<int, double>>(ValueRef::CloneUnique(rhs.value_ref))
)
);
}

value_ref_wrapper<double> operator*(const value_ref_wrapper<double>& lhs, double rhs) {
return value_ref_wrapper<double>(
std::make_shared<ValueRef::Operation<double>>(ValueRef::OpType::TIMES,
Expand Down Expand Up @@ -482,6 +491,35 @@ namespace {
nullptr
));
}

value_ref_wrapper<int> insert_parts_in_ship_design_(const boost::python::tuple& args, const boost::python::dict& kw) {
std::unique_ptr<ValueRef::ValueRef<std::string>> name;
if (kw.has_key("name")) {
auto name_args = boost::python::extract<value_ref_wrapper<std::string>>(kw["name"]);
if (name_args.check()) {
name = ValueRef::CloneUnique(name_args().value_ref);
} else {
name = std::make_unique<ValueRef::Constant<std::string>>(boost::python::extract<std::string>(kw["name"])());
}
}

std::unique_ptr<ValueRef::ValueRef<int>> design;
auto design_args = boost::python::extract<value_ref_wrapper<int>>(kw["design"]);
if (design_args.check()) {
design = ValueRef::CloneUnique(design_args().value_ref);
} else {
design = std::make_unique<ValueRef::Constant<int>>(boost::python::extract<int>(kw["design"])());
}

return value_ref_wrapper<int>(std::make_shared<ValueRef::ComplexVariable<int>>(
"PartsInShipDesign",
std::move(design),
nullptr,
nullptr,
std::move(name),
nullptr
));
}
}

void RegisterGlobalsValueRefs(boost::python::dict& globals, const PythonParser& parser) {
Expand Down Expand Up @@ -569,5 +607,6 @@ void RegisterGlobalsValueRefs(boost::python::dict& globals, const PythonParser&
globals["Statistic"] = boost::python::raw_function(f_insert_statistic, 2);

globals["DirectDistanceBetween"] = insert_direct_distance_between_;
globals["PartsInShipDesign"] = boost::python::raw_function(insert_parts_in_ship_design_);
}

1 change: 1 addition & 0 deletions parse/ValueRefPythonParser.h
Expand Up @@ -41,6 +41,7 @@ value_ref_wrapper<double> pow(const value_ref_wrapper<double>& lhs, double rhs);

value_ref_wrapper<double> operator*(int, const value_ref_wrapper<double>&);
value_ref_wrapper<double> operator*(const value_ref_wrapper<int>&, const value_ref_wrapper<double>&);
value_ref_wrapper<double> operator*(const value_ref_wrapper<double>&, const value_ref_wrapper<int>&);
value_ref_wrapper<double> operator*(const value_ref_wrapper<double>&, double);
value_ref_wrapper<double> operator*(double, const value_ref_wrapper<double>&);
value_ref_wrapper<double> operator*(double, const value_ref_wrapper<int>&);
Expand Down

0 comments on commit 7e2ef94

Please sign in to comment.