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

Function DrawSparkyDamageLightning

Descent3/renderobject.cpp:2223–2265  ·  view source on GitHub ↗

Creates lightning sparks on a damaged object

Source from the content-addressed store, hash-verified

2221}
2222// Creates lightning sparks on a damaged object
2223void DrawSparkyDamageLightning(object *obj) {
2224 float max_shields = 100;
2225 if (obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER || obj->type == OBJ_BUILDING)
2226 max_shields = Object_info[obj->id].hit_points;
2227 if (obj->type == OBJ_PLAYER)
2228 max_shields = INITIAL_SHIELDS;
2229 // If less than 30% shields, make some lightning every now and then
2230 if (max_shields > 0 && (obj->shields / max_shields) < .3 && obj->shields >= 0) {
2231 float shield_norm = (obj->shields / max_shields) / .3;
2232 shield_norm = 1 - shield_norm;
2233 ASSERT(shield_norm >= 0 && shield_norm <= 1);
2234 int shield_modulo = 20 - (12 * shield_norm);
2235 if (shield_modulo < 1)
2236 shield_modulo = 1;
2237 if ((ps_rand() % shield_modulo) == 0) {
2238 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
2239 if (pm->n_models == 0)
2240 return;
2241 int subnum = ps_rand() % pm->n_models;
2242 if (IsNonRenderableSubmodel(pm, subnum))
2243 return;
2244
2245 bsp_info *sm = &pm->submodel[subnum];
2246 if (sm->nverts == 0)
2247 return;
2248 int visnum = VisEffectCreate(VIS_FIREBALL, LIGHTNING_BOLT_INDEX, obj->roomnum, &obj->pos);
2249 if (visnum >= 0) {
2250 vis_effect *vis = &VisEffects[visnum];
2251 vis->lifeleft = 1.0;
2252 vis->lifetime = 1.0;
2253 vis->end_pos = obj->pos;
2254 vis->velocity.x = .15f;
2255 vis->velocity.y = 3;
2256 vis->attach_info.obj_handle = obj->handle;
2257 vis->attach_info.subnum = subnum;
2258 vis->attach_info.vertnum = ps_rand() % sm->nverts;
2259 vis->attach_info.end_vertnum = ps_rand() % sm->nverts;
2260 vis->attach_info.modelnum = obj->rtype.pobj_info.model_num;
2261 vis->flags = VF_USES_LIFELEFT | VF_EXPAND | VF_ATTACHED;
2262 }
2263 }
2264 }
2265}
2266
2267// Creates Virus infected lightning on an object
2268void DrawVirusLightning(object *obj) {

Callers 1

RenderObjectFunction · 0.85

Calls 3

ps_randFunction · 0.85
IsNonRenderableSubmodelFunction · 0.85
VisEffectCreateFunction · 0.85

Tested by

no test coverage detected