Skip to content

Commit fa250c5

Browse files
committed
add more advanced sexps for nebula poofs
1. Add new SEXP operators for setting and fading poofs that will work with one or more arguments, or no arguments (which will affect all poofs at once). 2. Update SEXP help, including clarification that the three `nebula-change-` operators require a nebula to be active to have any effect.
1 parent a3691ed commit fa250c5

File tree

6 files changed

+148
-45
lines changed

6 files changed

+148
-45
lines changed

code/nebula/neb.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ void neb2_level_init()
411411

412412
float nNf_near, nNf_density;
413413

414-
void neb2_poof_setup() {
414+
void neb2_poof_setup()
415+
{
415416
if (!any_bits_set(Neb2_poof_flags.get(), Poof_info.size()))
416417
return;
417418

@@ -833,11 +834,16 @@ void neb2_calc_poof_fades() {
833834
// WACKY LOCAL PLAYER NEBULA STUFF
834835
//
835836

836-
void neb2_toggle_poof(int poof_idx, bool enabling) {
837-
838-
if (enabling) set_bit(Neb2_poof_flags.get(), poof_idx);
839-
else clear_bit(Neb2_poof_flags.get(), poof_idx);
837+
void neb2_toggle_poof(int poof_idx, bool enabling)
838+
{
839+
if (enabling)
840+
set_bit(Neb2_poof_flags.get(), poof_idx);
841+
else
842+
clear_bit(Neb2_poof_flags.get(), poof_idx);
843+
}
840844

845+
void neb2_toggle_poof_finalize()
846+
{
841847
Neb2_poofs.clear();
842848

843849
// a bit awkward but this will force a full sphere gen
@@ -846,7 +852,7 @@ void neb2_toggle_poof(int poof_idx, bool enabling) {
846852
neb2_poof_setup();
847853
}
848854

849-
void neb2_fade_poofs(int poof_idx, int time, bool type)
855+
void neb2_fade_poof(int poof_idx, int time, bool type)
850856
{
851857
poof_info* pinfo = &Poof_info[poof_idx];
852858

code/nebula/neb.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ void neb2_render_setup(camid cid);
162162

163163
// turns a poof on or off
164164
void neb2_toggle_poof(int poof_idx, bool enabling);
165+
void neb2_toggle_poof_finalize(); // must be called after all poofs have been toggled
165166

166167
// fades poofs
167-
void neb2_fade_poofs(int poof_idx, int time, bool type);
168+
void neb2_fade_poof(int poof_idx, int time, bool type);
168169

169170
// render the player nebula
170171
void neb2_render_poofs();

code/parse/sexp.cpp

Lines changed: 124 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,9 @@ SCP_vector<sexp_oper> Operators = {
766766
{ "nebula-change-fog-color", OP_NEBULA_CHANGE_FOG_COLOR, 3, 3, SEXP_ACTION_OPERATOR, }, // Asteroth
767767
{ "nebula-change-storm", OP_NEBULA_CHANGE_STORM, 1, 1, SEXP_ACTION_OPERATOR, }, // phreak
768768
{ "nebula-toggle-poof", OP_NEBULA_TOGGLE_POOF, 2, 2, SEXP_ACTION_OPERATOR, }, // phreak
769+
{ "nebula-set-poofs", OP_NEBULA_SET_POOFS, 1, INT_MAX, SEXP_ACTION_OPERATOR, }, // Goober5000
769770
{ "nebula-fade-poof", OP_NEBULA_FADE_POOF, 3, 3, SEXP_ACTION_OPERATOR, }, // MjnMixael
771+
{ "nebula-fade-poofs", OP_NEBULA_FADE_POOFS, 2, INT_MAX, SEXP_ACTION_OPERATOR, }, // Goober5000
770772
{ "nebula-set-range", OP_NEBULA_SET_RANGE, 1, 1, SEXP_ACTION_OPERATOR, }, // Goober5000
771773
{ "volumetrics-toggle", OP_VOLUMETRICS_TOGGLE, 1, 1, SEXP_ACTION_OPERATOR, }, // Lafiel
772774
{ "set-skybox-model", OP_SET_SKYBOX_MODEL, 1, 8, SEXP_ACTION_OPERATOR, }, // taylor
@@ -16588,47 +16590,94 @@ void sexp_nebula_change_storm(int n)
1658816590
nebl_set_storm(CTEXT(n));
1658916591
}
1659016592

16591-
void sexp_nebula_toggle_poof(int n)
16593+
void sexp_nebula_set_poofs(int node, bool legacy)
1659216594
{
16593-
auto name = CTEXT(n);
16594-
bool result = is_sexp_true(CDR(n));
16595-
size_t i;
16595+
bool result;
16596+
int n = node;
1659616597

16597-
for (i = 0; i < Poof_info.size(); i++)
16598+
// new and legacy sexps have different argument orders
16599+
if (legacy)
16600+
result = is_sexp_true(CDR(n));
16601+
else
1659816602
{
16599-
if (!stricmp(name, Poof_info[i].name))
16600-
break;
16603+
result = is_sexp_true(n);
16604+
n = CDR(n);
16605+
}
16606+
16607+
// toggle all the poofs
16608+
if (n < 0)
16609+
{
16610+
int count = static_cast<int>(Poof_info.size());
16611+
for (int i = 0; i < count; ++i)
16612+
neb2_toggle_poof(i, result);
1660116613
}
16614+
// toggle the selected poofs
16615+
else
16616+
{
16617+
for (; n >= 0; n = CDR(n))
16618+
{
16619+
auto name = CTEXT(n);
16620+
16621+
int index = find_item_with_string(Poof_info, &poof_info::name, name);
16622+
if (index >= 0)
16623+
neb2_toggle_poof(index, result);
1660216624

16603-
//coulnd't find the poof
16604-
if (i == Poof_info.size()) return;
16625+
if (legacy)
16626+
break; // the legacy sexp affects only one poof
16627+
}
16628+
}
1660516629

16606-
neb2_toggle_poof(static_cast<int>(i), result);
16630+
// do this once at the end of all the toggling
16631+
neb2_toggle_poof_finalize();
1660716632
}
1660816633

16609-
void sexp_nebula_fade_poofs(int n)
16634+
void sexp_nebula_fade_poofs(int node, bool legacy)
1661016635
{
16611-
bool is_nan, is_nan_forever;
16612-
16613-
auto name = CTEXT(n);
16614-
n = CDR(n);
16615-
int time = eval_num(n, is_nan, is_nan_forever);
16616-
if (is_nan || is_nan_forever)
16617-
return;
16618-
n = CDR(n);
16619-
bool result = is_sexp_true(n);
16620-
size_t i;
16636+
bool result, is_nan, is_nan_forever;
16637+
int duration;
16638+
int n = node;
1662116639

16622-
for (i = 0; i < Poof_info.size(); i++) {
16623-
if (!stricmp(name, Poof_info[i].name))
16624-
break;
16640+
// new and legacy sexps have different argument orders
16641+
if (legacy)
16642+
{
16643+
duration = eval_num(CDR(n), is_nan, is_nan_forever);
16644+
if (is_nan || is_nan_forever)
16645+
return;
16646+
result = is_sexp_true(CDDR(n));
16647+
}
16648+
else
16649+
{
16650+
result = is_sexp_true(n);
16651+
n = CDR(n);
16652+
16653+
duration = eval_num(n, is_nan, is_nan_forever);
16654+
if (is_nan || is_nan_forever)
16655+
return;
16656+
n = CDR(n);
1662516657
}
1662616658

16627-
// coulnd't find the poof
16628-
if (i == Poof_info.size())
16629-
return;
16659+
// fade all the poofs
16660+
if (n < 0)
16661+
{
16662+
int count = static_cast<int>(Poof_info.size());
16663+
for (int i = 0; i < count; ++i)
16664+
neb2_fade_poof(i, duration, result);
16665+
}
16666+
// fade the specified poofs
16667+
else
16668+
{
16669+
for (; n >= 0; n = CDR(n))
16670+
{
16671+
auto name = CTEXT(n);
1663016672

16631-
neb2_fade_poofs(static_cast<int>(i), time, result);
16673+
int index = find_item_with_string(Poof_info, &poof_info::name, name);
16674+
if (index >= 0)
16675+
neb2_fade_poof(index, duration, result);
16676+
16677+
if (legacy)
16678+
break; // the legacy sexp affects only one poof
16679+
}
16680+
}
1663216681
}
1663316682

1663416683
void sexp_nebula_change_pattern(int n)
@@ -29017,12 +29066,14 @@ int eval_sexp(int cur_node, int referenced_node)
2901729066
break;
2901829067

2901929068
case OP_NEBULA_TOGGLE_POOF:
29020-
sexp_nebula_toggle_poof(node);
29069+
case OP_NEBULA_SET_POOFS:
29070+
sexp_nebula_set_poofs(node, op_num == OP_NEBULA_TOGGLE_POOF);
2902129071
sexp_val = SEXP_TRUE;
2902229072
break;
2902329073

2902429074
case OP_NEBULA_FADE_POOF:
29025-
sexp_nebula_fade_poofs(node);
29075+
case OP_NEBULA_FADE_POOFS:
29076+
sexp_nebula_fade_poofs(node, op_num == OP_NEBULA_FADE_POOF);
2902629077
sexp_val = SEXP_TRUE;
2902729078
break;
2902829079

@@ -31513,7 +31564,9 @@ int query_operator_return_type(int op)
3151331564
case OP_REMOVE_SUN_BITMAP:
3151431565
case OP_NEBULA_CHANGE_STORM:
3151531566
case OP_NEBULA_TOGGLE_POOF:
31567+
case OP_NEBULA_SET_POOFS:
3151631568
case OP_NEBULA_FADE_POOF:
31569+
case OP_NEBULA_FADE_POOFS:
3151731570
case OP_NEBULA_CHANGE_PATTERN:
3151831571
case OP_NEBULA_CHANGE_FOG_COLOR:
3151931572
case OP_NEBULA_SET_RANGE:
@@ -34248,6 +34301,12 @@ int query_operator_argument_type(int op, int argnum)
3424834301
else
3424934302
return OPF_BOOL;
3425034303

34304+
case OP_NEBULA_SET_POOFS:
34305+
if (argnum == 0)
34306+
return OPF_BOOL;
34307+
else
34308+
return OPF_NEBULA_POOF;
34309+
3425134310
case OP_NEBULA_FADE_POOF:
3425234311
if (argnum == 0)
3425334312
return OPF_NEBULA_POOF;
@@ -34256,6 +34315,14 @@ int query_operator_argument_type(int op, int argnum)
3425634315
else
3425734316
return OPF_BOOL;
3425834317

34318+
case OP_NEBULA_FADE_POOFS:
34319+
if (argnum == 0)
34320+
return OPF_BOOL;
34321+
else if (argnum == 1)
34322+
return OPF_POSITIVE;
34323+
else
34324+
return OPF_NEBULA_POOF;
34325+
3425934326
case OP_NEBULA_CHANGE_FOG_COLOR:
3426034327
case OP_NEBULA_SET_RANGE:
3426134328
return OPF_POSITIVE;
@@ -36579,7 +36646,9 @@ int get_category(int op_id)
3657936646
case OP_REMOVE_SUN_BITMAP:
3658036647
case OP_NEBULA_CHANGE_STORM:
3658136648
case OP_NEBULA_TOGGLE_POOF:
36649+
case OP_NEBULA_SET_POOFS:
3658236650
case OP_NEBULA_FADE_POOF:
36651+
case OP_NEBULA_FADE_POOFS:
3658336652
case OP_NEBULA_CHANGE_PATTERN:
3658436653
case OP_NEBULA_CHANGE_FOG_COLOR:
3658536654
case OP_NEBULA_SET_RANGE:
@@ -37223,7 +37292,9 @@ int get_subcategory(int op_id)
3722337292
case OP_REMOVE_SUN_BITMAP:
3722437293
case OP_NEBULA_CHANGE_STORM:
3722537294
case OP_NEBULA_TOGGLE_POOF:
37295+
case OP_NEBULA_SET_POOFS:
3722637296
case OP_NEBULA_FADE_POOF:
37297+
case OP_NEBULA_FADE_POOFS:
3722737298
case OP_NEBULA_CHANGE_PATTERN:
3722837299
case OP_NEBULA_CHANGE_FOG_COLOR:
3722937300
case OP_NEBULA_SET_RANGE:
@@ -41979,34 +42050,49 @@ SCP_vector<sexp_help_struct> Sexp_help = {
4197942050
},
4198042051

4198142052
{ OP_NEBULA_CHANGE_STORM, "nebula-change-storm\r\n"
41982-
"\tChanges the current nebula storm\r\n\r\n"
42053+
"\tChanges the current nebula storm. Has no effect if the nebula is not currently active.\r\n\r\n"
4198342054
"Takes 1 argument...\r\n"
4198442055
"\t1:\tNebula storm to change to\r\n"
4198542056
},
4198642057

41987-
{ OP_NEBULA_TOGGLE_POOF, "nebula-toggle-poof\r\n"
42058+
{ OP_NEBULA_TOGGLE_POOF, "nebula-toggle-poof (deprecated in favor of nebula-set-poofs)\r\n"
4198842059
"\tToggles the state of a nebula poof\r\n\r\n"
4198942060
"Takes 2 arguments...\r\n"
41990-
"\t1:\tName of nebula poof to toggle\r\n"
41991-
"\t2:\tA True boolean expression will toggle this poof on. A false one will do the opposite."
42061+
"\t1:\tName of the nebula poof to toggle\r\n"
42062+
"\t2:\tA true boolean expression will turn this poof on. A false one will turn this poof off."
42063+
},
42064+
42065+
{ OP_NEBULA_SET_POOFS, "nebula-set-poofs\r\n"
42066+
"\tSets the state of one or more nebula poofs\r\n\r\n"
42067+
"Takes 1 or more arguments...\r\n"
42068+
"\t1:\tA true boolean expression will turn the poofs on. A false one will turn them off.\r\n"
42069+
"\tRest:\tName of a nebula poof to set. If no poofs are listed, all tabled poofs will be set.\r\n"
4199242070
},
4199342071

41994-
{ OP_NEBULA_FADE_POOF, "nebula-fade-poof\r\n"
42072+
{ OP_NEBULA_FADE_POOF, "nebula-fade-poof (deprecated in favor of nebula-fade-poofs)\r\n"
4199542073
"\tSets a poof pattern to fade in or out over time\r\n"
4199642074
"Takes 3 arguments...\r\n"
4199742075
"\t1:\tName of the nebula poof to fade\r\n"
4199842076
"\t2:\tTime in milliseconds to fade\r\n"
41999-
"\t3:\tWhether or not to fade in or out. True to fade in, false to fade out\r\n"
42077+
"\t3:\tWhether to fade in or out. True to fade in, false to fade out\r\n"
42078+
},
42079+
42080+
{ OP_NEBULA_FADE_POOFS, "nebula-fade-poofs\r\n"
42081+
"\tSets one or more poof patterns to fade in or out over time\r\n"
42082+
"Takes 2 or more arguments...\r\n"
42083+
"\t1:\tWhether to fade in or out. True to fade in, false to fade out.\r\n"
42084+
"\t2:\tTime in milliseconds to fade.\r\n"
42085+
"\tRest:\tName of a nebula poof to fade. If no poofs are listed, all tabled poofs will be faded.\r\n"
4200042086
},
4200142087

4200242088
{ OP_NEBULA_CHANGE_PATTERN, "nebula-change-pattern\r\n"
42003-
"\tChanges the current nebula background pattern (as defined in nebula.tbl)\r\n\r\n"
42089+
"\tChanges the current nebula background pattern (as defined in nebula.tbl). Has no effect if the nebula is not currently active.\r\n\r\n"
4200442090
"Takes 1 argument...\r\n"
4200542091
"\t1:\tNebula background pattern to change to\r\n"
4200642092
},
4200742093

4200842094
{ OP_NEBULA_CHANGE_FOG_COLOR, "nebula-change-fog-color\r\n"
42009-
"\tChanges the current nebula fog color\r\n\r\n"
42095+
"\tChanges the current nebula fog color. Has no effect if the nebula is not currently active.\r\n\r\n"
4201042096
"Takes 3 arguments...\r\n"
4201142097
"\t1:\tRed (0 - 255)\r\n"
4201242098
"\t2:\tGreen (0 - 255)\r\n"

code/parse/sexp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,9 @@ enum : int {
703703
OP_REMOVE_SUN_BITMAP,
704704
OP_NEBULA_CHANGE_STORM,
705705
OP_NEBULA_TOGGLE_POOF,
706+
OP_NEBULA_SET_POOFS,
706707
OP_NEBULA_FADE_POOF,
708+
OP_NEBULA_FADE_POOFS,
707709
OP_VOLUMETRICS_TOGGLE,
708710

709711
OP_TURRET_CHANGE_WEAPON,

fred2/sexp_tree.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ void sexp_tree::right_clicked(int mode)
10241024
case OP_KEY_RESET:
10251025
case OP_SET_ASTEROID_FIELD:
10261026
case OP_SET_DEBRIS_FIELD:
1027+
case OP_NEBULA_TOGGLE_POOF:
1028+
case OP_NEBULA_FADE_POOF:
10271029
j = (int)op_menu.size(); // don't allow these operators to be visible
10281030
break;
10291031
}
@@ -1089,6 +1091,8 @@ void sexp_tree::right_clicked(int mode)
10891091
case OP_KEY_RESET:
10901092
case OP_SET_ASTEROID_FIELD:
10911093
case OP_SET_DEBRIS_FIELD:
1094+
case OP_NEBULA_TOGGLE_POOF:
1095+
case OP_NEBULA_FADE_POOF:
10921096
j = (int)op_submenu.size(); // don't allow these operators to be visible
10931097
break;
10941098
}

qtfred/src/ui/widgets/sexp_tree.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6409,6 +6409,8 @@ std::unique_ptr<QMenu> sexp_tree::buildContextMenu(QTreeWidgetItem* h) {
64096409
case OP_KEY_RESET:
64106410
case OP_SET_ASTEROID_FIELD:
64116411
case OP_SET_DEBRIS_FIELD:
6412+
case OP_NEBULA_TOGGLE_POOF:
6413+
case OP_NEBULA_FADE_POOF:
64126414
j = (int) op_menu.size(); // don't allow these operators to be visible
64136415
break;
64146416
}
@@ -6491,6 +6493,8 @@ std::unique_ptr<QMenu> sexp_tree::buildContextMenu(QTreeWidgetItem* h) {
64916493
case OP_KEY_RESET:
64926494
case OP_SET_ASTEROID_FIELD:
64936495
case OP_SET_DEBRIS_FIELD:
6496+
case OP_NEBULA_TOGGLE_POOF:
6497+
case OP_NEBULA_FADE_POOF:
64946498
j = (int) op_submenu.size(); // don't allow these operators to be visible
64956499
break;
64966500
}

0 commit comments

Comments
 (0)