MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / CreateAndAttach

Function CreateAndAttach

scripts/AIGame3.cpp:286–311  ·  view source on GitHub ↗

Returns the new child's handle

Source from the content-addressed store, hash-verified

284
285// Returns the new child's handle
286int CreateAndAttach(int me, const char *child_name, uint8_t child_type, char parent_ap, char child_ap, bool f_aligned,
287 bool f_set_parent) {
288 int child_handle = OBJECT_HANDLE_NONE;
289 int child_id = Obj_FindID(child_name);
290 msafe_struct m;
291 m.objhandle = me;
292 MSafe_GetValue(MSAFE_OBJECT_POS, &m);
293 MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &m);
294
295 if (child_id >= 0) {
296 int parent;
297 if (f_set_parent)
298 parent = me;
299 else
300 parent = OBJECT_HANDLE_NONE;
301
302 child_handle = Obj_Create(child_type, child_id, m.roomnum, &m.pos, NULL, parent);
303 if (child_handle != OBJECT_HANDLE_NONE) {
304 if (!Obj_AttachObjectAP(me, parent_ap, child_handle, child_ap, f_aligned)) {
305 // chrishack (we need a way to instantly kill scripted objects)
306 }
307 }
308 }
309
310 return child_handle;
311}
312
313int FindClosestPlayer(int objhandle) {
314 vector objpos, playerpos;

Callers 1

DoInitMethod · 0.70

Calls 1

Obj_CreateFunction · 0.85

Tested by

no test coverage detected