Skip to content

Commit

Permalink
Fonction setBlueprintAvailable sur le template de vaisseau
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsht committed Jan 14, 2024
1 parent 4d5d6b7 commit ca924a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions scripts/shiptemplates/40k/Croiseurs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ template:registerSquadronComposition("Ch", 5, 15, "Chasseur Mk2", "Chasseur", "C
template:registerSquadronComposition("Ch2", 5, 15, "Chasseur Mk2", "Chasseur", "Chasseur","Chasseur")
template:registerSquadronComposition("Ch3", 5, 15, "Chasseur Mk2", "Chasseur", "Chasseur","Chasseur")
template:registerSquadronComposition("Ch4", 5, 15, "Chasseur Mk2", "Chasseur", "Chasseur","Chasseur")
template:setBlueprintAvailable("Ch", "Ch3")

--Dock/balise de renfort de la marine

Expand Down
6 changes: 5 additions & 1 deletion src/shipTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,16 @@ REGISTER_SCRIPT_CLASS(ShipTemplate)
/// Defaults to true.
/// Example: template:setCanLaunchProbe(false)
REGISTER_SCRIPT_CLASS_FUNCTION(ShipTemplate, setCanLaunchProbe);
///Registers a new squandron type
///Registers a new squandron type (this is a kind of Blueprint)
///First argument registers the name of the squadron, this is an identifier (for instance "Interceptors")
///Second argument is maximum number of squadrons (ex: 5)
///Third argument is creation duration in seconds (ex : 30)
///Other arguments register the ship class name (for instance "Light Fighter Defiant class", "Viper", ...)
REGISTER_SCRIPT_CLASS_FUNCTION(ShipTemplate, registerSquadronComposition);
///Sets a blueprint available. By default, all blueprints are deactivated and not available for player
///You can specify a SquadronComposition name here, or any list.
///ex : setBlueprintAvailable("Ch", "Ch1", "Interceptors")
REGISTER_SCRIPT_CLASS_FUNCTION(ShipTemplate, setBlueprintAvailable);

/// Returns an exact copy of this ShipTemplate and sets the new copy's reference name to the given name, as ShipTemplate:setName().
/// The copy retains all other traits of the copied ShipTemplate.
Expand Down
13 changes: 13 additions & 0 deletions src/shipTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ class ShipTemplate : public PObject
squadrons_compositions.push_back(sqt);
}

void setBlueprintAvailable(const std::vector<string>& squadron_name)
{
std::unordered_set<string> template_names(squadron_name.begin(), squadron_name.end());
for(auto &sqt : squadrons_compositions)
{
if(template_names.find(sqt.template_name) != template_names.end())
{
sqt.available = true;
template_names.erase(sqt.template_name);
}
}
}

public:
static P<ShipTemplate> getTemplate(string name);
static std::vector<string> getAllTemplateNames();
Expand Down

0 comments on commit ca924a9

Please sign in to comment.