Debian Codegraph @

Descent3/attach.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20
21 #include "attach.h"cxx . . $ `<file>/Descent3/attach.h`/
22 #include "terrain.h"cxx . . $ `<file>/Descent3/terrain.h`/
23 #include "multi.h"cxx . . $ `<file>/Descent3/multi.h`/
24 #include "game.h"cxx . . $ `<file>/Descent3/game.h`/
25 #include "demofile.h"cxx . . $ `<file>/lib/demofile.h`/
26 #include "polymodel.h"cxx . . $ `<file>/model/polymodel.h`/
27 #include "objinfo.h"cxx . . $ `<file>/Descent3/objinfo.h`/
28
29 /* // Determines the necessary orientation and position of the moving object
30 f_use_uvec = true;
31 AttachPointPos(goal_obj, goal_ap, true, &goal_pos, true, &goal_fvec, &f_use_uvec, &goal_uvec);
32 goal_fvec *= -1.0f;
33
34 // Determines the initial attach fvec of the moving object
35 AttachPointPos(start_obj, start_ap, false, NULL, true, &start_fvec);
36
37 float dot = start_fvec * goal_fvec;
38 ASSERT(dot >= -1.1f && dot <= 1.1f);
39
40 // Bounds checking to save us from floating point round-off
41 if(dot > 1.0f)
42 dot = 1.0f;
43 if(dot < -1.0f)
44 dot = -1.0f;
45
46 // If the dot is 1.0 we are are already perfectly aligned!
47 if(dot != 1.0f)
48 {
49 // if it is -1.0, then we are perfectly unaligned
50 if(dot != -1.0f)
51 {
52 vm_CrossProduct(&rot_vec, &start_fvec, &goal_fvec);
53 vm_NormalizeVector(&rot_vec);
54
55 // returns the angle between two normalized vectors and a forward vector
56 // rot_angle = (vm_DeltaAngVecNorm(&start_fvec, &goal_fvec, &rot_vec)/65535.0f) * (2.0f * PI);
57 rot_angle = acos(dot);
58 }
59 else
60 {
61 vector random_vector;
62 float dot;
63
64 do
65 {
66 vm_MakeRandomVector(&random_vector);
67 vm_NormalizeVector(&random_vector);
68
69 dot = random_vector * goal_fvec;
70 }
71 while(dot >= 1.0f || dot <= -1.0f);
72
73 vm_CrossProduct(&rot_vec, &random_vector, &goal_fvec);
74 vm_NormalizeVector(&rot_vec);
75
76 rot_angle = PI;
77 }
78
79 ConvertAxisAmountMatrix(&rot_vec, rot_angle, &rot_mat);
80 vm_TransposeMatrix(&rot_mat);
81 start_obj->orient *= rot_mat;
82 }
83
84 // Determines the offset of the start object's ap position (now that it is correctly aligned
85 // with the fvec)
86 f_use_uvec = true;
87 vector temp;
88 AttachPointPos(start_obj, start_ap, true, &start_pos, true, &temp, &f_use_uvec, &start_uvec);
89
90 start_obj->pos += (goal_pos - start_pos);
91
92 // If we have UVEC's then align them!
93 if(f_use_uvec)
94 {
95 float dot = start_uvec * goal_uvec;
96 ASSERT(dot >= -1.1f && dot <= 1.1f);
97
98 // Bounds checking to save us from floating point round-off
99 if(dot > 1.0f)
100 dot = 1.0f;
101 if(dot < -1.0f)
102 dot = -1.0f;
103
104 // If the dot is 1.0 we are are already perfectly aligned!
105 if(dot != 1.0f)
106 {
107 // if it is -1.0, then we are perfectly unaligned
108 if(dot != -1.0f)
109 {
110 vm_CrossProduct(&rot_vec, &start_uvec, &goal_uvec);
111 vm_NormalizeVector(&rot_vec);
112
113 // rot_angle = (vm_DeltaAngVecNorm(&start_uvec, &goal_uvec, &rot_vec)/65535.0f) * (2.0f *
114 PI); rot_angle = acos(dot);
115 }
116 else
117 {
118 vector random_vector;
119 float dot;
120
121 do
122 {
123 vm_MakeRandomVector(&random_vector);
124 vm_NormalizeVector(&random_vector);
125
126 dot = random_vector * goal_uvec;
127 }
128 while(dot >= 1.0f || dot <= -1.0f);
129
130 vm_CrossProduct(&rot_vec, &random_vector, &goal_uvec);
131 vm_NormalizeVector(&rot_vec);
132
133 rot_angle = PI;
134 }
135
136 ConvertAxisAmountMatrix(&rot_vec, rot_angle, &rot_mat);
137 vm_TransposeMatrix(&rot_mat);
138 start_obj->orient *= rot_mat;
139 }
140 }
141 */
142
143 // Finds the position of a attach point on an object
144 // The uvec is optional as most attaching objects don't need at complete orientation set (only an fvec)
145 static bool AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(objectcxx . . $ object# *obj, char ap, bool f_compute_pos, vectorcxx . . $ vector# *attach_pos, bool f_compute_fvec,
146 vectorcxx . . $ vector# *attach_fvec, bool *f_computed_uvec = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, vectorcxx . . $ vector# *attach_uvec = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
147 poly_modelcxx . . $ poly_model# *pm;
148 vectorcxx . . $ vector# pnt;
149 vectorcxx . . $ vector# normal;
150 vectorcxx . . $ vector# uvec;
151 matrixcxx . . $ matrix# m;
152 int mn; // submodel number
153 float normalized_time[MAX_SUBOBJECTScxx . . $ `lib/polymodel_external.h:76:9`!];
154
155 pm = &Poly_modelscxx . . $ Poly_models.[obj->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
156
157 if (ap < 0 || ap >= pm->n_attachcxx . . $ poly_model#n_attach.) {
158 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "WARNING: No ap %d on object %d.\n", ap, OBJNUM(obj));
159 return false;
160 }
161
162 SetNormalizedTimeObjcxx . . $ SetNormalizedTimeObj(8af4de573afdac78).(obj, normalized_time);
163 SetModelAnglesAndPoscxx . . $ SetModelAnglesAndPos(a00e94110fc4ea4c).(pm, normalized_time);
164
165 if (f_compute_pos)
166 pnt =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). pm->attach_slotscxx . . $ poly_model#attach_slots.[ap].pntcxx . . $ a_bank#pnt.;
167
168 if (f_compute_fvec) {
169 normal =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). pm->attach_slotscxx . . $ poly_model#attach_slots.[ap].normcxx . . $ a_bank#norm.;
170 // mprintf(0, "Original fvec is %f long.\n", vm_GetMagnitude(&normal));
171 }
172
173 if (pm->attach_slotscxx . . $ poly_model#attach_slots.[ap].f_uveccxx . . $ a_bank#f_uvec. && attach_uvec && f_computed_uvec) {
174 *f_computed_uvec = true;
175 uvec =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). pm->attach_slotscxx . . $ poly_model#attach_slots.[ap].uveccxx . . $ a_bank#uvec.;
176
177 // mprintf(0, "Original uvec is %f long.\n", vm_GetMagnitude(&uvec));
178 } else if (f_computed_uvec) {
179 *f_computed_uvec = false;
180 }
181
182 mn = pm->attach_slotscxx . . $ poly_model#attach_slots.[ap].parentcxx . . $ a_bank#parent.;
183
184 // Instance up the tree for this gun
185 while (mn != -1) {
186 vectorcxx . . $ vector# tpnt;
187
188 vm_AnglesToMatrixcxx . . $ vm_AnglesToMatrix(654fa9e3c9c3be99).(&m, pm->submodelcxx . . $ poly_model#submodel.[mn].angscxx . . $ bsp_info#angs..pcxx . . $ angvec#p., pm->submodelcxx . . $ poly_model#submodel.[mn].angscxx . . $ bsp_info#angs..hcxx . . $ angvec#h., pm->submodelcxx . . $ poly_model#submodel.[mn].angscxx . . $ bsp_info#angs..bcxx . . $ angvec#b.);
189 vm_TransposeMatrixcxx . . $ vm_TransposeMatrix(dca75c48c9ab5b54).(&m);
190
191 if (f_compute_pos)
192 tpnt =cxx . . $ vector#`operator=`(c0842353a20857d). pnt *cxx . . $ `operator*`(14b8f9ac5c1e7b85). m;
193
194 if (f_compute_fvec)
195 normal =cxx . . $ vector#`operator=`(c0842353a20857d). normal *cxx . . $ `operator*`(14b8f9ac5c1e7b85). m;
196
197 if (f_computed_uvec && *f_computed_uvec) {
198 uvec =cxx . . $ vector#`operator=`(c0842353a20857d). uvec *cxx . . $ `operator*`(14b8f9ac5c1e7b85). m;
199 }
200
201 if (f_compute_pos)
202 pnt =cxx . . $ vector#`operator=`(c0842353a20857d). tpnt +cxx . . $ operator+(b77b703cd1e43e33). pm->submodelcxx . . $ poly_model#submodel.[mn].offsetcxx . . $ bsp_info#offset. +cxx . . $ operator+(b77b703cd1e43e33). pm->submodelcxx . . $ poly_model#submodel.[mn].mod_poscxx . . $ bsp_info#mod_pos.;
203
204 mn = pm->submodelcxx . . $ poly_model#submodel.[mn].parentcxx . . $ bsp_info#parent.;
205 }
206
207 // now instance for the entire object
208 m =cxx . . $ matrix#`operator=`(4c6f8b29806742). obj->orientcxx . . $ object#orient.;
209 vm_TransposeMatrixcxx . . $ vm_TransposeMatrix(dca75c48c9ab5b54).(&m);
210
211 if (f_compute_pos)
212 *attach_pos =cxx . . $ vector#`operator=`(c0842353a20857d). pnt *cxx . . $ `operator*`(14b8f9ac5c1e7b85). m;
213
214 if (f_compute_fvec) {
215 *attach_fvec =cxx . . $ vector#`operator=`(c0842353a20857d). normal *cxx . . $ `operator*`(14b8f9ac5c1e7b85). m;
216 // mprintf(0, "Rotated fvec is %f long.\n", vm_GetMagnitude(attach_fvec));
217 }
218
219 if (f_computed_uvec && *f_computed_uvec) {
220 *attach_uvec =cxx . . $ vector#`operator=`(c0842353a20857d). uvec *cxx . . $ `operator*`(14b8f9ac5c1e7b85). m;
221 // mprintf(0, "Rotated uvec is %f long.\n", vm_GetMagnitude(attach_uvec));
222 }
223
224 if (f_compute_pos)
225 *attach_pos +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). obj->poscxx . . $ object#pos.;
226
227 return true;
228 }
229
230 static void ConvertAxisAmountMatrixcxx . . $ ConvertAxisAmountMatrix(8286a54c08c7ddb9).(vectorcxx . . $ vector# *n, float w, matrixcxx . . $ matrix# *rotmat) {
231 float s;
232 float c;
233 float t;
234
235 // float scale = *w/.0001f;
236 // float w_n = .0001f;
237 // vector s_result;
238
239 if (w == 0.0f) {
240 matrixcxx . . $ matrix# temp = IDENTITY_MATRIXcxx . . $ `lib/vecmat_external.h:55:9`!;
241
242 *rotmat =cxx . . $ matrix#`operator=`(4c6f8b29806742). temp;
243 return;
244 }
245
246 s = sincxx . . $ sin(fbcf3211dfe1bfd1).(w);
247 c = coscxx . . $ cos(fbcf3211dfe1bfd1).(w);
248 t = 1.0f - c;
249
250 const float sx = s * n->xcxx . . $ vector#x.;
251 const float sy = s * n->ycxx . . $ vector#y.;
252 const float sz = s * n->zcxx . . $ vector#z.;
253 const float txy = t * n->xcxx . . $ vector#x. * n->ycxx . . $ vector#y.;
254 const float txz = t * n->xcxx . . $ vector#x. * n->zcxx . . $ vector#z.;
255 const float tyz = t * n->ycxx . . $ vector#y. * n->zcxx . . $ vector#z.;
256 const float txx = t * n->xcxx . . $ vector#x. * n->xcxx . . $ vector#x.;
257 const float tyy = t * n->ycxx . . $ vector#y. * n->ycxx . . $ vector#y.;
258 const float tzz = t * n->zcxx . . $ vector#z. * n->zcxx . . $ vector#z.;
259
260 rotmat->rveccxx . . $ matrix#rvec..xcxx . . $ vector#x. = txx + c;
261 rotmat->rveccxx . . $ matrix#rvec..ycxx . . $ vector#y. = txy - sz;
262 rotmat->rveccxx . . $ matrix#rvec..zcxx . . $ vector#z. = txz + sy;
263 rotmat->uveccxx . . $ matrix#uvec..xcxx . . $ vector#x. = txy + sz;
264 rotmat->uveccxx . . $ matrix#uvec..ycxx . . $ vector#y. = tyy + c;
265 rotmat->uveccxx . . $ matrix#uvec..zcxx . . $ vector#z. = tyz - sx;
266 rotmat->fveccxx . . $ matrix#fvec..xcxx . . $ vector#x. = txz - sy;
267 rotmat->fveccxx . . $ matrix#fvec..ycxx . . $ vector#y. = tyz + sx;
268 rotmat->fveccxx . . $ matrix#fvec..zcxx . . $ vector#z. = tzz + c;
269 }
270
271 bool AttachDoPosOrientRadcxx . . $ AttachDoPosOrientRad(5918c311dcb3dd22).(objectcxx . . $ object# *parent, char p_ap, objectcxx . . $ object# *child, float rad_percent, vectorcxx . . $ vector# *pos) {
272 vectorcxx . . $ vector# attach_pos;
273 vectorcxx . . $ vector# attach_fvec;
274
275 if (AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(parent, p_ap, true, &attach_pos, true, &attach_fvec)) {
276 vectorcxx . . $ vector# child_ap_pos = child->poscxx . . $ object#pos. -cxx . . $ operator-(b77b703cd1e43e33). attach_fvec *cxx . . $ `operator*`(252247219a31502c). (rad_percent * child->sizecxx . . $ object#size.);
277
278 *pos =cxx . . $ vector#`operator=`(c0842353a20857d). (child_ap_pos -cxx . . $ operator-(b77b703cd1e43e33). attach_pos) +cxx . . $ operator+(b77b703cd1e43e33). parent->poscxx . . $ object#pos.;
279 return true;
280 } else {
281 return false;
282 }
283 }
284
285 bool AttachDoPosOrientcxx . . $ AttachDoPosOrient(abf0e4ef1467cf92).(objectcxx . . $ object# *parent, char parent_ap, objectcxx . . $ object# *child, char child_ap, bool f_parent, bool f_move_obj,
286 vectorcxx . . $ vector# *pos, matrixcxx . . $ matrix# *orient, bool f_dropping_off) {
287 vectorcxx . . $ vector# goal_fvec;
288 vectorcxx . . $ vector# goal_uvec;
289 vectorcxx . . $ vector# goal_pos;
290
291 bool f_use_uvec = true;
292
293 vectorcxx . . $ vector# start_fvec;
294 vectorcxx . . $ vector# start_uvec;
295 vectorcxx . . $ vector# start_pos;
296
297 objectcxx . . $ object# *goal_obj;
298 objectcxx . . $ object# *start_obj;
299
300 matrixcxx . . $ matrix# rot_mat;
301
302 char goal_ap;
303 char start_ap;
304
305 if (f_parent) {
306 goal_obj = child;
307 goal_ap = child_ap;
308
309 start_obj = parent;
310 start_ap = parent_ap;
311 } else {
312 goal_obj = parent;
313 goal_ap = parent_ap;
314
315 start_obj = child;
316 start_ap = child_ap;
317 }
318
319 vectorcxx . . $ vector# saved_pos = start_obj->poscxx . . $ object#pos.;
320 matrixcxx . . $ matrix# saved_orient = start_obj->orientcxx . . $ object#orient.;
321
322 f_use_uvec = true;
323 AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(goal_obj, goal_ap, true, &goal_pos, true, &goal_fvec, &f_use_uvec, &goal_uvec);
324 goal_fvec *=cxx . . $ `operator*=`(f132838b2cd11d6). -1.0f;
325
326 f_use_uvec = true;
327 if (f_dropping_off) {
328 objectcxx . . $ object# *attached_obj = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(start_obj->attach_childrencxx . . $ object#attach_children.[0]);
329 ASSERTcxx . . $ `misc/pserror.h:246:9`!(attached_obj);
330 AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(attached_obj, start_ap, true, &start_pos, true, &start_fvec, &f_use_uvec, &start_uvec);
331 } else {
332 AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(start_obj, start_ap, true, &start_pos, true, &start_fvec, &f_use_uvec, &start_uvec);
333 }
334
335 vm_NormalizeVectorcxx . . $ vm_NormalizeVector(4939a7e530383cd4).(&start_fvec);
336 vm_NormalizeVectorcxx . . $ vm_NormalizeVector(4939a7e530383cd4).(&start_uvec);
337 vm_NormalizeVectorcxx . . $ vm_NormalizeVector(4939a7e530383cd4).(&goal_fvec);
338 vm_NormalizeVectorcxx . . $ vm_NormalizeVector(4939a7e530383cd4).(&goal_uvec);
339
340 matrixcxx . . $ matrix# start_m;
341 matrixcxx . . $ matrix# goal_m;
342
343 vm_VectorToMatrixcxx . . $ vm_VectorToMatrix(543233b88555916d).(&start_m, &start_fvec, &start_uvec, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
344 vm_VectorToMatrixcxx . . $ vm_VectorToMatrix(543233b88555916d).(&goal_m, &goal_fvec, &goal_uvec, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
345
346 matrixcxx . . $ matrix# sot;
347 matrixcxx . . $ matrix# srt;
348
349 sot =cxx . . $ matrix#`operator=`(4c6f8b29806742). start_obj->orientcxx . . $ object#orient.;
350 vm_TransposeMatrixcxx . . $ vm_TransposeMatrix(dca75c48c9ab5b54).(&sot);
351
352 srt =cxx . . $ matrix#`operator=`(e859ffc26b91394f). sot *cxx . . $ `operator*`(683f8e040c904cb). start_m;
353 vm_TransposeMatrixcxx . . $ vm_TransposeMatrix(dca75c48c9ab5b54).(&srt);
354
355 rot_mat =cxx . . $ matrix#`operator=`(e859ffc26b91394f). sot *cxx . . $ `operator*`(683f8e040c904cb). goal_m *cxx . . $ `operator*`(683f8e040c904cb). srt;
356
357 start_obj->orientcxx . . $ object#orient. *=cxx . . $ `operator*=`(3149f8f1fe1d09b5). rot_mat;
358 vm_Orthogonalizecxx . . $ vm_Orthogonalize(dca75c48c9ab5b54).(&start_obj->orientcxx . . $ object#orient.);
359
360 if (f_dropping_off) {
361 objectcxx . . $ object# *attached_obj = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(start_obj->attach_childrencxx . . $ object#attach_children.[0]);
362 ASSERTcxx . . $ `misc/pserror.h:246:9`!(attached_obj);
363 AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(attached_obj, start_ap, true, &start_pos, false, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
364 } else {
365 AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(start_obj, start_ap, true, &start_pos, false, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
366 }
367 start_obj->poscxx . . $ object#pos. +=cxx . . $ `operator+=`(801a8d6f7ab7bef9). (goal_pos -cxx . . $ operator-(b77b703cd1e43e33). start_pos);
368
369 if (pos)
370 *pos =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). start_obj->poscxx . . $ object#pos.;
371
372 if (orient)
373 *orient =cxx . . $ matrix#`operator=`(4c6f8b29806742). start_obj->orientcxx . . $ object#orient.;
374
375 if (f_move_obj) {
376 int room = goal_obj->roomnumcxx . . $ object#roomnum.;
377 if (room != -1) {
378 if (ROOMNUM_OUTSIDEcxx . . $ `lib/object_external_struct.h:127:9`!(room)) {
379 room = GetTerrainRoomFromPoscxx . . $ GetTerrainRoomFromPos(177d9005acf670a0).(&start_obj->poscxx . . $ object#pos.);
380 if (room == -1) {
381 SetObjectDeadFlagcxx . . $ SetObjectDeadFlag(80a724877f6428f2).(start_obj);
382 return false;
383 }
384 }
385
386 ObjSetPoscxx . . $ ObjSetPos(bbb518390bedd509).(start_obj, &start_obj->poscxx . . $ object#pos., room, &start_obj->orientcxx . . $ object#orient., false);
387
388 return true;
389 } else {
390 SetObjectDeadFlagcxx . . $ SetObjectDeadFlag(80a724877f6428f2).(start_obj);
391 return false;
392 }
393 } else {
394 start_obj->poscxx . . $ object#pos. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). saved_pos;
395 start_obj->orientcxx . . $ object#orient. =cxx . . $ matrix#`operator=`(4c6f8b29806742). saved_orient;
396 }
397
398 return true;
399 }
400
401 // Adds and subtracts from mass from connections and disconnections
402 static void AttachPropagateMasscxx . . $ AttachPropagateMass(674fac047436fc5b).(objectcxx . . $ object# *child, bool f_attach = true) {
403 objectcxx . . $ object# *new_parent;
404
405 if (!child)
406 return;
407
408 do {
409 new_parent = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(child->attach_parent_handlecxx . . $ object#attach_parent_handle.);
410 ASSERTcxx . . $ `misc/pserror.h:246:9`!(new_parent);
411 if (!new_parent) {
412 return;
413 }
414
415 float mass;
416
417 mass = Object_infocxx . . $ Object_info.[child->idcxx . . $ object#id.].phys_infocxx . . $ object_info#phys_info..masscxx . . $ physics_info#mass.;
418
419 if (mass < 0.0f)
420 mass = 0.0f;
421
422 ASSERTcxx . . $ `misc/pserror.h:246:9`!(new_parent->mtype.phys_info.mass >= 0.0f && mass >= 0.0f);
423
424 if (f_attach)
425 new_parent->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..masscxx . . $ physics_info#mass. += mass;
426 else
427 new_parent->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..masscxx . . $ physics_info#mass. -= mass;
428
429 if (new_parent->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..masscxx . . $ physics_info#mass. < 0.0f) {
430 new_parent->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..masscxx . . $ physics_info#mass. = 0.0f;
431 }
432
433 child = new_parent;
434
435 ASSERTcxx . . $ `misc/pserror.h:246:9`!(new_parent->mtype.phys_info.mass >= 0.0f);
436 } while (child->flagscxx . . $ object#flags. & OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!);
437 }
438
439 static inline void ComputeUltimateAttachParentcxx . . $ ComputeUltimateAttachParent(419c470199a90a97).(objectcxx . . $ object# *child) {
440 objectcxx . . $ object# *cur_obj = child;
441
442 do {
443 child->attach_ultimate_handlecxx . . $ object#attach_ultimate_handle. = cur_obj->attach_parent_handlecxx . . $ object#attach_parent_handle.;
444 cur_obj = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(child->attach_ultimate_handlecxx . . $ object#attach_ultimate_handle.);
445 ASSERTcxx . . $ `misc/pserror.h:246:9`!(cur_obj);
446
447 } while (cur_obj->flagscxx . . $ object#flags. & OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!);
448 }
449
450 static void ProprogateUltimateAttachParentcxx . . $ ProprogateUltimateAttachParent(766a1b7183ffa4b4).(objectcxx . . $ object# *parent, int ultimate_handle) {
451 int i;
452
453 ASSERTcxx . . $ `misc/pserror.h:246:9`!(parent);
454 ASSERTcxx . . $ `misc/pserror.h:246:9`!(ultimate_handle != OBJECT_HANDLE_NONEcxx . . $ `Descent3/object_external.h:156:9`!);
455
456 poly_modelcxx . . $ poly_model# *parent_pm = &Poly_modelscxx . . $ Poly_models.[parent->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
457
458 if (!parent->attach_childrencxx . . $ object#attach_children.)
459 return;
460
461 for (i = 0; i < parent_pm->n_attachcxx . . $ poly_model#n_attach.; i++) {
462 objectcxx . . $ object# *child;
463
464 if ((child = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(parent->attach_childrencxx . . $ object#attach_children.[i])) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
465 child->attach_ultimate_handlecxx . . $ object#attach_ultimate_handle. = ultimate_handle;
466 ProprogateUltimateAttachParentcxx . . $ ProprogateUltimateAttachParent(766a1b7183ffa4b4).(child, ultimate_handle);
467 }
468 }
469 }
470
471 // Attaches 2 objects via attach points on each. The f_used_aligned allows for an aligned connection.
472 // NOTE: The child always moves to the parent
473 bool AttachObjectcxx . . $ AttachObject(f6b18a350068acc8).(objectcxx . . $ object# *parent, char parent_ap, objectcxx . . $ object# *child, char child_ap, bool f_use_aligned) {
474 ASSERTcxx . . $ `misc/pserror.h:246:9`!(parent);
475 ASSERTcxx . . $ `misc/pserror.h:246:9`!(child);
476
477 poly_modelcxx . . $ poly_model# *parent_pm = &Poly_modelscxx . . $ Poly_models.[parent->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
478 poly_modelcxx . . $ poly_model# *child_pm = &Poly_modelscxx . . $ Poly_models.[child->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
479
480 if (parent_ap < 0 || parent_ap >= parent_pm->n_attachcxx . . $ poly_model#n_attach.) {
481 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: Parent AP invalid\n");
482 return false;
483 }
484
485 if (child->flagscxx . . $ object#flags. & OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!) {
486 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: Child already attached to someone\n");
487 return false;
488 }
489
490 if (child_ap >= 0 && child_ap < child_pm->n_attachcxx . . $ poly_model#n_attach.) {
491 if (AttachDoPosOrientcxx . . $ AttachDoPosOrient(abf0e4ef1467cf92).(parent, parent_ap, child, child_ap, false)) {
492 child->flagscxx . . $ object#flags. |= OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!;
493 child->attach_typecxx . . $ object#attach_type. = AT_ALIGNEDcxx . . $ `Descent3/object_external.h:253:9`!;
494 child->attach_indexcxx . . $ object#$anonymous_type_7#attach_index. = child_ap;
495 child->attach_parent_handlecxx . . $ object#attach_parent_handle. = parent->handlecxx . . $ object#handle.;
496
497 parent->attach_childrencxx . . $ object#attach_children.[parent_ap] = child->handlecxx . . $ object#handle.;
498 ComputeUltimateAttachParentcxx . . $ ComputeUltimateAttachParent(419c470199a90a97).(child);
499 ProprogateUltimateAttachParentcxx . . $ ProprogateUltimateAttachParent(766a1b7183ffa4b4).(child, child->attach_ultimate_handlecxx . . $ object#attach_ultimate_handle.);
500
501 AttachPropagateMasscxx . . $ AttachPropagateMass(674fac047436fc5b).(child);
502
503 AttachUpdateSubObjectscxx . . $ AttachUpdateSubObjects(419c470199a90a97).(child);
504 if ((Game_modecxx . . $ Game_mode. & GM_MULTIcxx . . $ `Descent3/game.h:288:9`!) && (Netgamecxx . . $ Netgame..local_rolecxx . . $ netgame_info#local_role. == LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!)) {
505 MultiSendAttachcxx . . $ MultiSendAttach(5e1f903503988afd).(parent, parent_ap, child, child_ap, f_use_aligned);
506 }
507 if (Demo_flagscxx . . $ Demo_flags. == DF_RECORDINGcxx . . $ `lib/demofile.h:122:9`!) {
508 DemoWriteAttachObjcxx . . $ DemoWriteAttachObj(5e1f903503988afd).(parent, parent_ap, child, child_ap, f_use_aligned);
509 }
510
511 return true;
512 }
513
514 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: AP attach failed\n");
515 return false;
516 }
517
518 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: Child AP (%d) - child only has %d attach points\n", child_ap, child_pm->n_attach);
519 return false;
520 }
521
522 // Attaches a child object to a parent object by a percent of the radius of the child.
523 // NOTE: The child always moves to the parent and not the reverse
524 bool AttachObjectcxx . . $ AttachObject(45561ecb6c1b979f).(objectcxx . . $ object# *parent, char parent_ap, objectcxx . . $ object# *child, float percent_rad) {
525 ASSERTcxx . . $ `misc/pserror.h:246:9`!(parent);
526 ASSERTcxx . . $ `misc/pserror.h:246:9`!(child);
527
528 poly_modelcxx . . $ poly_model# *parent_pm = &Poly_modelscxx . . $ Poly_models.[parent->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
529 poly_modelcxx . . $ poly_model# *child_pm = &Poly_modelscxx . . $ Poly_models.[parent->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
530
531 if (parent_ap < 0 || parent_ap >= parent_pm->n_attachcxx . . $ poly_model#n_attach.) {
532 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: Parent AP invalid\n");
533 return false;
534 }
535
536 if (child->flagscxx . . $ object#flags. & OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!) {
537 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: Child already attached to someone\n");
538 return false;
539 }
540
541 if (percent_rad >= 0.0f) {
542 vectorcxx . . $ vector# attach_pos;
543 vectorcxx . . $ vector# attach_fvec;
544
545 if (AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(parent, parent_ap, true, &attach_pos, true, &attach_fvec)) {
546 child->flagscxx . . $ object#flags. |= OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!;
547 child->attach_typecxx . . $ object#attach_type. = AT_RADcxx . . $ `Descent3/object_external.h:252:9`!;
548 child->attach_distcxx . . $ object#$anonymous_type_7#attach_dist. = percent_rad * child->sizecxx . . $ object#size.;
549 child->attach_parent_handlecxx . . $ object#attach_parent_handle. = parent->handlecxx . . $ object#handle.;
550
551 parent->attach_childrencxx . . $ object#attach_children.[parent_ap] = child->handlecxx . . $ object#handle.;
552 ComputeUltimateAttachParentcxx . . $ ComputeUltimateAttachParent(419c470199a90a97).(child);
553 ProprogateUltimateAttachParentcxx . . $ ProprogateUltimateAttachParent(766a1b7183ffa4b4).(child, child->attach_ultimate_handlecxx . . $ object#attach_ultimate_handle.);
554
555 AttachPropagateMasscxx . . $ AttachPropagateMass(674fac047436fc5b).(child);
556
557 vectorcxx . . $ vector# new_child_pos = attach_pos +cxx . . $ operator+(b77b703cd1e43e33). attach_fvec *cxx . . $ `operator*`(252247219a31502c). child->attach_distcxx . . $ object#$anonymous_type_7#attach_dist.;
558
559 int room = parent->roomnumcxx . . $ object#roomnum.;
560 if (ROOMNUM_OUTSIDEcxx . . $ `lib/object_external_struct.h:127:9`!(room))
561 room = GetTerrainRoomFromPoscxx . . $ GetTerrainRoomFromPos(177d9005acf670a0).(&new_child_pos);
562
563 ObjSetPoscxx . . $ ObjSetPos(bbb518390bedd509).(child, &new_child_pos, room, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, false);
564
565 AttachUpdateSubObjectscxx . . $ AttachUpdateSubObjects(419c470199a90a97).(child);
566 if ((Game_modecxx . . $ Game_mode. & GM_MULTIcxx . . $ `Descent3/game.h:288:9`!) && (Netgamecxx . . $ Netgame..local_rolecxx . . $ netgame_info#local_role. == LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!)) {
567 MultiSendAttachRadcxx . . $ MultiSendAttachRad(dd3c3fb04585c0c5).(parent, parent_ap, child, percent_rad);
568 }
569 if (Demo_flagscxx . . $ Demo_flags. == DF_RECORDINGcxx . . $ `lib/demofile.h:122:9`!) {
570 DemoWriteAttachObjRadcxx . . $ DemoWriteAttachObjRad(dd3c3fb04585c0c5).(parent, parent_ap, child, percent_rad);
571 }
572
573 return true;
574 }
575
576 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: RAD attach failed\n");
577 return false;
578 }
579
580 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ATTACH: Child percent rad is invalid\n");
581 return false;
582 }
583
584 // Updates the position of all the subobjects off the ultimate attach parent
585 void AttachUpdateSubObjectscxx . . $ AttachUpdateSubObjects(419c470199a90a97).(objectcxx . . $ object# *parent) {
586 poly_modelcxx . . $ poly_model# *parent_pm = &Poly_modelscxx . . $ Poly_models.[parent->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
587 int i;
588
589 #ifdef _DEBUGcxx . . $ `<built-in>:482:9`!
590 if (!Game_update_attachcxx . . $ Game_update_attach.)
591 return;
592 #endif
593
594 if (parent->attach_childrencxx . . $ object#attach_children. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
595 return;
596
597 for (i = 0; i < parent_pm->n_attachcxx . . $ poly_model#n_attach.; i++) {
598 objectcxx . . $ object# *child;
599
600 if ((child = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(parent->attach_childrencxx . . $ object#attach_children.[i])) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
601 ASSERTcxx . . $ `misc/pserror.h:246:9`!(child->flags & OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!);
602
603 child->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..velocitycxx . . $ physics_info#velocity. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). parent->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..velocitycxx . . $ physics_info#velocity.;
604 child->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..rotvelcxx . . $ physics_info#$anonymous_type_1#rotvel. =cxx . . $ vector#`operator=`(a48bc7e93a8dae5e). parent->mtypecxx . . $ object#mtype..phys_infocxx . . $ object#$anonymous_type_8#phys_info..rotvelcxx . . $ physics_info#$anonymous_type_1#rotvel.;
605
606 switch (child->attach_typecxx . . $ object#attach_type.) {
607 case AT_UNALIGNEDcxx . . $ `Descent3/object_external.h:254:9`!:
608 AttachDoPosOrientcxx . . $ AttachDoPosOrient(abf0e4ef1467cf92).(parent, i, child, child->attach_indexcxx . . $ object#$anonymous_type_7#attach_index., false);
609 break;
610 case AT_ALIGNEDcxx . . $ `Descent3/object_external.h:253:9`!:
611 AttachDoPosOrientcxx . . $ AttachDoPosOrient(abf0e4ef1467cf92).(parent, i, child, child->attach_indexcxx . . $ object#$anonymous_type_7#attach_index., false);
612 break;
613 case AT_RADcxx . . $ `Descent3/object_external.h:252:9`!: {
614 vectorcxx . . $ vector# attach_pos;
615 vectorcxx . . $ vector# attach_fvec;
616
617 if (AttachPointPoscxx . . $ AttachPointPos(d0b169c55f620168).(parent, i, true, &attach_pos, true, &attach_fvec)) {
618 vectorcxx . . $ vector# new_child_pos = attach_pos +cxx . . $ operator+(b77b703cd1e43e33). attach_fvec *cxx . . $ `operator*`(252247219a31502c). child->attach_distcxx . . $ object#$anonymous_type_7#attach_dist.;
619
620 int room = parent->roomnumcxx . . $ object#roomnum.;
621 if (ROOMNUM_OUTSIDEcxx . . $ `lib/object_external_struct.h:127:9`!(room))
622 room = GetTerrainRoomFromPoscxx . . $ GetTerrainRoomFromPos(177d9005acf670a0).(&new_child_pos);
623
624 ObjSetPoscxx . . $ ObjSetPos(bbb518390bedd509).(child, &new_child_pos, room, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, false);
625 } else {
626 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get chris
627 }
628 } break;
629 default:
630 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Non-supported attach type - Get Chris
631 }
632
633 AttachUpdateSubObjectscxx . . $ AttachUpdateSubObjects(419c470199a90a97).(child);
634 }
635 }
636 }
637
638 // Unattaches an object from its parent
639 bool UnattachFromParentcxx . . $ UnattachFromParent(39516aeee13ca5ab).(objectcxx . . $ object# *child) {
640 if (!(child->flagscxx . . $ object#flags. & OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!))
641 return false;
642
643 AttachPropagateMasscxx . . $ AttachPropagateMass(674fac047436fc5b).(child, false);
644
645 objectcxx . . $ object# *parent = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(child->attach_parent_handlecxx . . $ object#attach_parent_handle.);
646 ASSERTcxx . . $ `misc/pserror.h:246:9`!(parent);
647
648 poly_modelcxx . . $ poly_model# *parent_pm = &Poly_modelscxx . . $ Poly_models.[parent->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
649 int i;
650
651 for (i = 0; i < parent_pm->n_attachcxx . . $ poly_model#n_attach.; i++) {
652 if (parent->attach_childrencxx . . $ object#attach_children.[i] == child->handlecxx . . $ object#handle.) {
653 parent->attach_childrencxx . . $ object#attach_children.[i] = OBJECT_HANDLE_NONEcxx . . $ `Descent3/object_external.h:156:9`!;
654 break;
655 }
656 }
657
658 // ASSERT(i < parent_pm->n_attach); // Didn't find its parent? Get chris!
659
660 child->flagscxx . . $ object#flags. &= ~OF_ATTACHEDcxx . . $ `Descent3/object_external.h:273:9`!;
661 child->attach_parent_handlecxx . . $ object#attach_parent_handle. = OBJECT_HANDLE_NONEcxx . . $ `Descent3/object_external.h:156:9`!;
662 child->attach_ultimate_handlecxx . . $ object#attach_ultimate_handle. = OBJECT_HANDLE_NONEcxx . . $ `Descent3/object_external.h:156:9`!;
663
664 ProprogateUltimateAttachParentcxx . . $ ProprogateUltimateAttachParent(766a1b7183ffa4b4).(child, child->handlecxx . . $ object#handle.);
665 if ((Game_modecxx . . $ Game_mode. & GM_MULTIcxx . . $ `Descent3/game.h:288:9`!) && (Netgamecxx . . $ Netgame..local_rolecxx . . $ netgame_info#local_role. == LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!)) {
666 MultiSendUnattachcxx . . $ MultiSendUnattach(419c470199a90a97).(child);
667 }
668 if (Demo_flagscxx . . $ Demo_flags. == DF_RECORDINGcxx . . $ `lib/demofile.h:122:9`!) {
669 DemoWriteUnattachObjcxx . . $ DemoWriteUnattachObj(419c470199a90a97).(child);
670 }
671
672 return true;
673 }
674
675 // Unattaches a child from an attach point
676 bool UnattachChildcxx . . $ UnattachChild(9646b7081aeecba4).(objectcxx . . $ object# *parent, char parent_ap) {
677 objectcxx . . $ object# *child;
678
679 if ((child = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(parent->attach_childrencxx . . $ object#attach_children.[parent_ap])) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
680 return UnattachFromParentcxx . . $ UnattachFromParent(39516aeee13ca5ab).(child);
681 }
682
683 return false;
684 }
685
686 // Unattaches all children from a parent object
687 bool UnattachChildrencxx . . $ UnattachChildren(39516aeee13ca5ab).(objectcxx . . $ object# *parent) {
688 poly_modelcxx . . $ poly_model# *parent_pm = &Poly_modelscxx . . $ Poly_models.[parent->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..model_numcxx . . $ polyobj_info#model_num.];
689 int i;
690
691 if (!parent->attach_childrencxx . . $ object#attach_children.)
692 return false;
693
694 for (i = 0; i < parent_pm->n_attachcxx . . $ poly_model#n_attach.; i++) {
695 objectcxx . . $ object# *child;
696
697 if ((child = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(parent->attach_childrencxx . . $ object#attach_children.[i])) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
698 UnattachFromParentcxx . . $ UnattachFromParent(39516aeee13ca5ab).(child);
699 }
700 }
701
702 return true;
703 }