Skip to content

Commit

Permalink
Merge pull request #5566 from Goober5000/allowed_in_campaign
Browse files Browse the repository at this point in the history
add AllowedInCampaign virtvar
  • Loading branch information
Goober5000 authored Oct 14, 2023
2 parents 08dfcc8 + 210a9a8 commit 7a4df25
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions code/scripting/api/objs/shipclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ship/ship.h"
#include "playerman/player.h"
#include "weapon/weapon.h"
#include "mission/missioncampaign.h"
#include "missionui/missionweaponchoice.h"
#include "graphics/matrix.h"
#include "missionui/missionscreencommon.h"
Expand Down Expand Up @@ -1070,6 +1071,23 @@ ADE_VIRTVAR(InTechDatabase, l_Shipclass, "boolean", "Gets or sets whether this s
return ade_set_args(L, "b", Ship_info[idx].flags[flag]);
}

ADE_VIRTVAR(AllowedInCampaign, l_Shipclass, "boolean", "Gets or sets whether this ship class is allowed in loadouts in campaign mode", "boolean", "True or false")
{
int idx;
bool new_value;
if (!ade_get_args(L, "o|b", l_Shipclass.Get(&idx), &new_value))
return ade_set_error(L, "b", false);

if (idx < 0 || idx >= ship_info_size())
return ade_set_error(L, "b", false);

if (ADE_SETTING_VAR) {
Campaign.ships_allowed[idx] = new_value;
}

return Campaign.ships_allowed[idx] ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
}

ADE_VIRTVAR(PowerOutput, l_Shipclass, "number", "Gets or sets a ship class' power output", "number", "The ship class' current power output")
{
int idx;
Expand Down
18 changes: 18 additions & 0 deletions code/scripting/api/objs/weaponclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "weapon/weapon.h"
#include "graphics/matrix.h"
#include "vecmath.h"
#include "mission/missioncampaign.h"
#include "missionui/missionscreencommon.h"
#include "model/modelrender.h"

Expand Down Expand Up @@ -637,6 +638,23 @@ ADE_VIRTVAR(InTechDatabase, l_Weaponclass, "boolean", "Gets or sets whether this
return ade_set_args(L, "b", Weapon_info[idx].wi_flags[Weapon::Info_Flags::In_tech_database]);
}

ADE_VIRTVAR(AllowedInCampaign, l_Weaponclass, "boolean", "Gets or sets whether this weapon class is allowed in loadouts in campaign mode", "boolean", "True or false")
{
int idx;
bool new_value;
if (!ade_get_args(L, "o|b", l_Weaponclass.Get(&idx), &new_value))
return ade_set_error(L, "b", false);

if (idx < 0 || idx >= weapon_info_size())
return ade_set_error(L, "b", false);

if (ADE_SETTING_VAR) {
Campaign.weapons_allowed[idx] = new_value;
}

return Campaign.weapons_allowed[idx] ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
}

ADE_VIRTVAR(CargoSize, l_Weaponclass, "number", "The cargo size of this weapon class", "number", "The new cargo size or -1 on error")
{
int idx;
Expand Down

0 comments on commit 7a4df25

Please sign in to comment.