1818#include " graphics/matrix.h"
1919#include " missionui/missionscreencommon.h"
2020#include " scripting/api/objs/weaponclass.h"
21+ #include " scripting/lua/LuaTable.h"
2122#include " model/modelrender.h"
2223#include " utils/string_utils.h"
2324
@@ -1146,7 +1147,7 @@ ADE_FUNC(isInTechroom, l_Shipclass, NULL, "Gets whether or not the ship class is
11461147ADE_FUNC (renderTechModel,
11471148 l_Shipclass,
11481149 " number X1, number Y1, number X2, number Y2, [number RotationPercent =0, number PitchPercent =0, number "
1149- " BankPercent=40, number Zoom=1.3, boolean Lighting=true, teamcolor TeamColor=nil]" ,
1150+ " BankPercent=40, number Zoom=1.3, boolean Lighting=true, teamcolor TeamColor=nil, string[] DestroyedSubsystems=nil ]" ,
11501151 " Draws ship model as if in techroom. True for regular lighting, false for flat lighting." ,
11511152 " boolean" ,
11521153 " Whether ship was rendered" )
@@ -1157,7 +1158,8 @@ ADE_FUNC(renderTechModel,
11571158 float zoom = 1 .3f ;
11581159 bool lighting = true ;
11591160 int tc_idx = -1 ;
1160- if (!ade_get_args (L, " oiiii|ffffbo" , l_Shipclass.Get (&idx), &x1, &y1, &x2, &y2, &rot_angles.h , &rot_angles.p , &rot_angles.b , &zoom, &lighting, l_TeamColor.Get (&tc_idx)))
1161+ auto destroyed_subsystems_table = luacpp::LuaTable::create (L);
1162+ if (!ade_get_args (L, " oiiii|ffffbot" , l_Shipclass.Get (&idx), &x1, &y1, &x2, &y2, &rot_angles.h , &rot_angles.p , &rot_angles.b , &zoom, &lighting, l_TeamColor.Get (&tc_idx), &destroyed_subsystems_table))
11611163 return ade_set_error (L, " b" , false );
11621164
11631165 if (idx < 0 || idx >= ship_info_size ())
@@ -1190,18 +1192,35 @@ ADE_FUNC(renderTechModel,
11901192 }
11911193 }
11921194
1193- return ade_set_args (L, " b" , render_tech_model (TECH_SHIP , x1, y1, x2, y2, zoom, lighting, idx, &orient, " " , 0 .0f , &vmd_zero_vector, tcolor));
1195+ SCP_vector<SCP_string> destroyed_subsystems;
1196+ if (destroyed_subsystems_table.isValid ()) {
1197+ for (const auto & item : destroyed_subsystems_table) {
1198+ if (!item.second .is (luacpp::ValueType::STRING )) {
1199+ LuaError (L, " DestroyedSubsystems must be a table of strings." );
1200+ return ade_set_args (L, " b" , false );
1201+ }
1202+
1203+ try {
1204+ destroyed_subsystems.emplace_back (item.second .getValue <SCP_string>());
1205+ } catch (const luacpp::LuaException& /* e*/ ) {
1206+ return ade_set_args (L, " b" , false );
1207+ }
1208+ }
1209+ }
1210+
1211+ return ade_set_args (L, " b" , render_tech_model (TECH_SHIP , x1, y1, x2, y2, zoom, lighting, idx, &orient, " " , 0 .0f , &vmd_zero_vector, tcolor, destroyed_subsystems));
11941212}
11951213
11961214// Nuke's alternate tech model rendering function
1197- ADE_FUNC (renderTechModel2, l_Shipclass, " number X1, number Y1, number X2, number Y2, [orientation Orientation=nil, number Zoom=1.3, teamcolor TeamColor=nil]" , " Draws ship model as if in techroom" , " boolean" , " Whether ship was rendered" )
1215+ ADE_FUNC (renderTechModel2, l_Shipclass, " number X1, number Y1, number X2, number Y2, [orientation Orientation=nil, number Zoom=1.3, teamcolor TeamColor=nil, string[] DestroyedSubsystems=nil ]" , " Draws ship model as if in techroom" , " boolean" , " Whether ship was rendered" )
11981216{
11991217 int x1,y1,x2,y2;
12001218 int idx;
12011219 float zoom = 1 .3f ;
12021220 matrix_h *mh = nullptr ;
12031221 int tc_idx = -1 ;
1204- if (!ade_get_args (L, " oiiiio|fo" , l_Shipclass.Get (&idx), &x1, &y1, &x2, &y2, l_Matrix.GetPtr (&mh), &zoom, l_TeamColor.Get (&tc_idx)))
1222+ auto destroyed_subsystems_table = luacpp::LuaTable::create (L);
1223+ if (!ade_get_args (L, " oiiiio|fot" , l_Shipclass.Get (&idx), &x1, &y1, &x2, &y2, l_Matrix.GetPtr (&mh), &zoom, l_TeamColor.Get (&tc_idx), &destroyed_subsystems_table))
12051224 return ade_set_error (L, " b" , false );
12061225
12071226 if (idx < 0 || idx >= ship_info_size ())
@@ -1223,7 +1242,23 @@ ADE_FUNC(renderTechModel2, l_Shipclass, "number X1, number Y1, number X2, number
12231242 }
12241243 }
12251244
1226- return ade_set_args (L, " b" , render_tech_model (TECH_SHIP , x1, y1, x2, y2, zoom, true , idx, orient, " " , 0 .0f , &vmd_zero_vector, tcolor));
1245+ SCP_vector<SCP_string> destroyed_subsystems;
1246+ if (destroyed_subsystems_table.isValid ()) {
1247+ for (const auto & item : destroyed_subsystems_table) {
1248+ if (!item.second .is (luacpp::ValueType::STRING )) {
1249+ LuaError (L, " DestroyedSubsystems must be a table of strings." );
1250+ return ade_set_args (L, " b" , false );
1251+ }
1252+
1253+ try {
1254+ destroyed_subsystems.emplace_back (item.second .getValue <SCP_string>());
1255+ } catch (const luacpp::LuaException& /* e*/ ) {
1256+ return ade_set_args (L, " b" , false );
1257+ }
1258+ }
1259+ }
1260+
1261+ return ade_set_args (L, " b" , render_tech_model (TECH_SHIP , x1, y1, x2, y2, zoom, true , idx, orient, " " , 0 , &vmd_zero_vector, tcolor, destroyed_subsystems));
12271262}
12281263
12291264ADE_FUNC (renderSelectModel,
0 commit comments