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

Function AttachRandomNapalmEffectsToObject

Descent3/viseffect.cpp:2224–2287  ·  view source on GitHub ↗

Attaches viseffects that move with an object

Source from the content-addressed store, hash-verified

2222
2223// Attaches viseffects that move with an object
2224void AttachRandomNapalmEffectsToObject(object *obj) {
2225 if (obj->flags & OF_DEAD)
2226 return;
2227
2228 vector velocity_norm = obj->mtype.phys_info.velocity;
2229 vm_NormalizeVector(&velocity_norm);
2230 vector pos = obj->pos - (velocity_norm * (obj->size / 2));
2231
2232 if (obj->movement_type == MT_PHYSICS && (OBJECT_OUTSIDE(obj) && (ps_rand() % 3) == 0) || (ps_rand() % 3) == 0)
2233 CreateFireball(&pos, BLACK_SMOKE_INDEX, obj->roomnum, VISUAL_FIREBALL);
2234
2235 float size_scalar = obj->size / 7.0;
2236
2237 size_scalar = std::clamp(size_scalar, 1.0f, 4.0f);
2238
2239 // Create an explosion that follows every now and then
2240 if ((ps_rand() % 3) == 0) {
2241 if (!(obj->flags & OF_POLYGON_OBJECT))
2242 return;
2243
2244 int num = 1;
2245
2246 num += (obj->size / 15);
2247
2248 for (int i = 0; i < num; i++) {
2249 vector dest;
2250 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
2251
2252 if (pm->n_models == 0)
2253 return;
2254
2255 int subnum = ps_rand() % pm->n_models;
2256
2257 if (IsNonRenderableSubmodel(pm, subnum))
2258 continue;
2259
2260 bsp_info *sm = &pm->submodel[subnum];
2261
2262 if (sm->nverts == 0)
2263 return;
2264
2265 int vertnum = ps_rand() % sm->nverts;
2266
2267 GetPolyModelPointInWorld(&dest, &Poly_models[obj->rtype.pobj_info.model_num], &obj->pos, &obj->orient, subnum,
2268 &sm->verts[vertnum]);
2269 int visnum = VisEffectCreate(VIS_FIREBALL, GetRandomSmallExplosion(), obj->roomnum, &dest);
2270 if (visnum == -1)
2271 return;
2272
2273 VisEffects[visnum].size += ((ps_rand() % 20) / 20.0) * 1.0;
2274
2275 VisEffects[visnum].size *= size_scalar;
2276
2277 if ((ps_rand() % 2)) {
2278 if (obj->movement_type == MT_PHYSICS) {
2279 VisEffects[visnum].movement_type = MT_PHYSICS;
2280 VisEffects[visnum].velocity = obj->mtype.phys_info.velocity;
2281 VisEffects[visnum].mass = obj->mtype.phys_info.mass;

Callers 1

ObjDoEffectsFunction · 0.85

Calls 7

vm_NormalizeVectorFunction · 0.85
ps_randFunction · 0.85
CreateFireballFunction · 0.85
IsNonRenderableSubmodelFunction · 0.85
GetPolyModelPointInWorldFunction · 0.85
VisEffectCreateFunction · 0.85
GetRandomSmallExplosionFunction · 0.85

Tested by

no test coverage detected