Skip to content

Commit 06c6faa

Browse files
committed
Expose functions to instantly finish current moveable
1 parent 15c4141 commit 06c6faa

5 files changed

Lines changed: 77 additions & 1 deletion

File tree

code/model/animation/modelanimation.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,12 +1062,31 @@ namespace animation {
10621062
return true;
10631063
}
10641064

1065+
bool ModelAnimationSet::advanceMoveableToFinal(polymodel_instance* pmi, const SCP_string& name) const {
1066+
SCP_string lowername = name;
1067+
SCP_tolower(lowername);
1068+
auto moveable = m_moveableSet.find(lowername);
1069+
if (moveable == m_moveableSet.end())
1070+
return false;
1071+
1072+
moveable->second->advanceToFinalState(pmi);
1073+
return true;
1074+
}
1075+
10651076
void ModelAnimationSet::initializeMoveables(polymodel_instance* pmi) {
10661077
for(const auto& moveable : m_moveableSet){
10671078
moveable.second->initialize(this, pmi);
10681079
}
10691080
}
10701081

1082+
void ModelAnimationMoveable::advanceToFinalState(polymodel_instance* pmi) {
1083+
auto it = m_instances.find(pmi->id);
1084+
if (it == m_instances.end() || !it->second.animation)
1085+
return;
1086+
1087+
it->second.animation->start(pmi, ModelAnimationDirection::FWD, true, true);
1088+
}
1089+
10711090
SCP_vector<SCP_string> ModelAnimationSet::getRegisteredMoveables() const {
10721091
SCP_vector<SCP_string> ret;
10731092

code/model/animation/modelanimation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ namespace animation {
286286

287287
virtual void update(polymodel_instance* pmi, const SCP_vector<std::any>& args) = 0;
288288
virtual void initialize(ModelAnimationSet* parentSet, polymodel_instance* pmi) = 0;
289+
290+
void advanceToFinalState(polymodel_instance* pmi);
289291
};
290292

291293

@@ -368,6 +370,7 @@ namespace animation {
368370
SCP_set<SCP_string> getRegisteredAnimNames() const;
369371

370372
bool updateMoveable(polymodel_instance* pmi, const SCP_string& name, const SCP_vector<std::any>& args) const;
373+
bool advanceMoveableToFinal(polymodel_instance* pmi, const SCP_string& name) const;
371374
void initializeMoveables(polymodel_instance* pmi);
372375
SCP_vector<SCP_string> getRegisteredMoveables() const;
373376

code/parse/sexp.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ SCP_vector<sexp_oper> Operators = {
627627
{ "trigger-ship-animation", OP_TRIGGER_ANIMATION_NEW, 3, 7, SEXP_ACTION_OPERATOR, }, //Lafiel
628628
{ "stop-looping-animation", OP_STOP_LOOPING_ANIMATION, 3, 3, SEXP_ACTION_OPERATOR, }, //Lafiel
629629
{ "update-moveable-animation", OP_UPDATE_MOVEABLE, 2, INT_MAX, SEXP_ACTION_OPERATOR, }, //Lafiel
630+
{ "advance-moveable-animation", OP_ADVANCE_MOVEABLE, 2, 2, SEXP_ACTION_OPERATOR, }, //Lafiel
630631

631632
//Coordinate Manipulation Sub-Category
632633
{ "set-object-position", OP_SET_OBJECT_POSITION, 4, 4, SEXP_ACTION_OPERATOR, }, // WMC
@@ -2870,7 +2871,8 @@ int check_sexp_syntax(int node, int desired_return_type, int recursive, int *bad
28702871

28712872
break;
28722873
}
2873-
case OP_UPDATE_MOVEABLE: {
2874+
case OP_UPDATE_MOVEABLE:
2875+
case OP_ADVANCE_MOVEABLE:{
28742876
//Second OP name
28752877
SCP_string name = CTEXT(CDR(ship_node));
28762878
SCP_tolower(name);
@@ -23557,6 +23559,19 @@ void sexp_update_moveable_animation(int node)
2355723559
Ship_info[ship_entry->shipp()->ship_info_index].animations.updateMoveable(model_get_instance(ship_entry->shipp()->model_instance_num), name, args);
2355823560
}
2355923561

23562+
void sexp_advance_moveable_animation(int node)
23563+
{
23564+
auto ship_entry = eval_ship(node);
23565+
if (!ship_entry || !ship_entry->has_shipp())
23566+
return;
23567+
23568+
node = CDR(node);
23569+
23570+
SCP_string name(CTEXT(node));
23571+
23572+
Ship_info[ship_entry->shipp()->ship_info_index].animations.advanceMoveableToFinal(model_get_instance(ship_entry->shipp()->model_instance_num), name);
23573+
}
23574+
2356023575
void sexp_add_remove_escort(int node)
2356123576
{
2356223577
int flag;
@@ -30675,6 +30690,11 @@ int eval_sexp(int cur_node, int referenced_node)
3067530690
sexp_update_moveable_animation(node);
3067630691
break;
3067730692

30693+
case OP_ADVANCE_MOVEABLE:
30694+
sexp_val = SEXP_TRUE;
30695+
sexp_advance_moveable_animation(node);
30696+
break;
30697+
3067830698
case OP_STOP_LOOPING_ANIMATION:
3067930699
sexp_val = SEXP_TRUE;
3068030700
sexp_stop_looping_animation(node);
@@ -32013,6 +32033,7 @@ int query_operator_return_type(int op)
3201332033
case OP_SET_ALPHA_MULT:
3201432034
case OP_TRIGGER_ANIMATION_NEW:
3201532035
case OP_UPDATE_MOVEABLE:
32036+
case OP_ADVANCE_MOVEABLE:
3201632037
case OP_STOP_LOOPING_ANIMATION:
3201732038
case OP_CONTAINER_ADD_TO_LIST:
3201832039
case OP_CONTAINER_REMOVE_FROM_LIST:
@@ -34939,6 +34960,12 @@ int query_operator_argument_type(int op_index, int argnum)
3493934960
else
3494034961
return OPF_NUMBER;
3494134962

34963+
case OP_ADVANCE_MOVEABLE:
34964+
if (argnum == 0)
34965+
return OPF_SHIP;
34966+
else
34967+
return OPF_ANIMATION_NAME;
34968+
3494234969
case OP_IS_CONTAINER_EMPTY:
3494334970
case OP_GET_CONTAINER_SIZE:
3494434971
if (argnum == 0) {
@@ -37210,6 +37237,7 @@ int get_category(int op_id)
3721037237
case OP_DESTROY_INSTANTLY_WITH_DEBRIS:
3721137238
case OP_TRIGGER_ANIMATION_NEW:
3721237239
case OP_UPDATE_MOVEABLE:
37240+
case OP_ADVANCE_MOVEABLE:
3721337241
case OP_NAV_SET_COLOR:
3721437242
case OP_NAV_SET_VISITED_COLOR:
3721537243
case OP_CONTAINER_ADD_TO_LIST:
@@ -37547,6 +37575,7 @@ int get_subcategory(int op_id)
3754737575
case OP_SET_ALPHA_MULT:
3754837576
case OP_TRIGGER_ANIMATION_NEW:
3754937577
case OP_UPDATE_MOVEABLE:
37578+
case OP_ADVANCE_MOVEABLE:
3755037579
case OP_STOP_LOOPING_ANIMATION:
3755137580
return CHANGE_SUBCATEGORY_MODELS_AND_TEXTURES;
3755237581

@@ -42871,6 +42900,13 @@ SCP_vector<sexp_help_struct> Sexp_help = {
4287142900
"\tThree optional numbers: x, y, z rotation target relative to base, in degrees\r\n"
4287242901
},
4287342902

42903+
{ OP_ADVANCE_MOVEABLE, "advance-moveable-animation\r\n"
42904+
"\tAdvances a moveable animation to its final state instantly.\r\n"
42905+
"Takes 2 arguments...\r\n"
42906+
"\t1: The ship (ship must be in-mission).\r\n"
42907+
"\t2: The name of the moveable.\r\n"
42908+
},
42909+
4287442910
{ OP_TOGGLE_ASTEROID_FIELD, "toggle-asteroid-field\r\n"
4287542911
"\tTurns an existing asteroid or debris field on/off. Will do nothing if no field is defined in the mission file or set with sexps.\r\n"
4287642912
"\tNote that this differs from actually removing and adding a field in that it only toggles a field from being rendered or calculated.\r\n"

code/parse/sexp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ enum : int {
899899
OP_DESTROY_INSTANTLY_WITH_DEBRIS, // Asteroth
900900
OP_TRIGGER_ANIMATION_NEW, // Lafiel
901901
OP_UPDATE_MOVEABLE, // Lafiel
902+
OP_ADVANCE_MOVEABLE, // Lafiel
902903
OP_NAV_SET_COLOR, // Goober5000
903904
OP_NAV_SET_VISITED_COLOR, // Goober5000
904905
OP_CONTAINER_ADD_TO_LIST, // Karajorma/jg18

code/scripting/api/objs/ship.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,23 @@ ADE_FUNC(updateSubmodelMoveable, l_Ship, "string name, table values",
23112311
return Ship_info[shipp->ship_info_index].animations.updateMoveable(model_get_instance(shipp->model_instance_num), name, valuesMoveable) ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
23122312
}
23132313

2314+
ADE_FUNC(advanceSubmodelMoveableToFinal, l_Ship, "string name",
2315+
"Advances a moveable animation to its final state immediately. Name is the name of the moveable.",
2316+
"boolean", "True if successful, false or nil otherwise")
2317+
{
2318+
object_h* objh;
2319+
const char* name = nullptr;
2320+
2321+
if (!ade_get_args(L, "os", l_Ship.GetPtr(&objh), &name))
2322+
return ADE_RETURN_NIL;
2323+
2324+
if (!objh->isValid())
2325+
return ADE_RETURN_NIL;
2326+
2327+
ship* shipp = &Ships[objh->objp()->instance];
2328+
return Ship_info[shipp->ship_info_index].animations.advanceMoveableToFinal(model_get_instance(shipp->model_instance_num), name) ? ADE_RETURN_TRUE : ADE_RETURN_FALSE;
2329+
}
2330+
23142331
ADE_FUNC(warpIn, l_Ship, NULL, "Warps ship in", "boolean", "True if successful, or nil if ship handle is invalid")
23152332
{
23162333
object_h *objh;

0 commit comments

Comments
 (0)