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

Function AllocObjectID

Descent3/objinfo.cpp:115–189  ·  view source on GitHub ↗

Allocs a object for use, returns -1 if error, else index on success

Source from the content-addressed store, hash-verified

113
114// Allocs a object for use, returns -1 if error, else index on success
115int AllocObjectID(int type, bool f_anim, bool f_weapons, bool f_ai) {
116 int j, k;
117
118 for (int i = NUM_STATIC_OBJECTS; i < MAX_OBJECT_IDS; i++) {
119 if (Object_info[i].type == OBJ_NONE) {
120 mprintf(1, "%d ", type);
121 memset(&Object_info[i], 0, sizeof(*Object_info));
122
123 extern void AISetDefault(t_ai_info * ai_info_ptr);
124 if (f_ai) {
125 Object_info[i].ai_info = (t_ai_info *)mem_malloc(sizeof(t_ai_info));
126 memset(Object_info[i].ai_info, 0, sizeof(t_ai_info));
127 AISetDefault(Object_info[i].ai_info);
128 }
129 // Make sure the weapon battery info is cleared for a new object
130 if (f_weapons) {
131 Object_info[i].static_wb = (otype_wb_info *)mem_malloc(sizeof(otype_wb_info) * MAX_WBS_PER_OBJ);
132 memset(Object_info[i].static_wb, 0, sizeof(otype_wb_info) * MAX_WBS_PER_OBJ);
133 WBClearInfo(Object_info[i].static_wb);
134 }
135
136 if (f_anim) {
137 Object_info[i].anim = (anim_elem *)mem_malloc(sizeof(anim_elem) * NUM_MOVEMENT_CLASSES);
138 memset(Object_info[i].anim, 0, sizeof(anim_elem) * NUM_MOVEMENT_CLASSES);
139 for (j = 0; j < NUM_MOVEMENT_CLASSES; j++)
140 for (k = 0; k < NUM_ANIMS_PER_CLASS; k++) {
141 Object_info[i].anim[j].elem[k].spc = 1.0f;
142 Object_info[i].anim[j].elem[k].anim_sound_index = SOUND_NONE_INDEX;
143 }
144 }
145
146 Object_info[i].type = type;
147 Object_info[i].size = DEFAULT_OBJECT_SIZE;
148 Object_info[i].phys_info.mass = DEFAULT_OBJECT_MASS;
149 Object_info[i].phys_info.drag = DEFAULT_OBJECT_DRAG;
150 Object_info[i].phys_info.rotdrag = DEFAULT_OBJECT_ROTDRAG;
151
152 Object_info[i].phys_info.flags = PF_BOUNCE;
153 Object_info[i].phys_info.num_bounces = -1;
154 Object_info[i].phys_info.coeff_restitution = 1.0;
155 Object_info[i].phys_info.hit_die_dot = -1; //-1 mean doesn't apply
156
157 Object_info[i].med_render_handle = -1;
158 Object_info[i].lo_render_handle = -1;
159 Object_info[i].med_lod_distance = DEFAULT_MED_LOD_DISTANCE;
160 Object_info[i].lo_lod_distance = DEFAULT_LO_LOD_DISTANCE;
161 Object_info[i].respawn_scalar = 1.0;
162
163 if (type == OBJ_CLUTTER || type == OBJ_ROBOT) {
164 Object_info[i].med_lod_distance *= 10;
165 Object_info[i].lo_lod_distance *= 10;
166 }
167
168 // Object_info[i].script_name[0] = 0;
169 Object_info[i].icon_name[0] = 0;
170 Object_info[i].description = NULL;
171 Object_info[i].flags |= OIF_INVEN_SELECTABLE;
172

Callers 4

mng_SetAndLoadGenericFunction · 0.85
OnGenericAddNewMethod · 0.85
OnGenericPasteMethod · 0.85
RemapStaticIDsFunction · 0.85

Calls 2

AISetDefaultFunction · 0.85
WBClearInfoFunction · 0.70

Tested by

no test coverage detected