void effect::drawaura(rpgent *d, float size, int type, int elapse) { if(size <= 0) return; size *= this->size; int fade, gravity, num; setvars(this, type, fade, gravity, num); num *= .2 * PI * d->radius / (1 + size) * partmul * (elapse ? logf(elapse) / 3 : 1); if(elapse && !num && rnd(int(10 / partmul))) return; //sometimes particles should not be drawn num = max<int>(1, num); loopi(num) { vec pos = vec(rnd(360) * RAD, 0).mul(d->radius + size).add(d->feetpos()); switch(particle) { case PART_EXPLOSION: case PART_EXPLOSION_BLUE: particle_fireball(pos, size, particle, fade, colour, size); break; case PART_STREAK: case PART_LIGHTNING: if(!curtime) return; particle_flare(pos, vec(0, 0, d->eyeheight + d->aboveeye).add(pos), fade, particle, colour, size); break; default: if(gravity >= 0) pos.add(vec(0, 0, d->eyeheight + d->aboveeye)); particle_splash(particle, 2, fade, pos, colour, size, max<int>(1, size * 2), gravity); break; } } }
void effect::drawcone(vec &o, vec dir, vec &axis, int angle, float radius, float size, int type, int elapse) { if(size <= 0) return; size *= this->size; int fade, gravity, num; setvars(this, type, fade, gravity, num); num *= angle * (particle == PART_STREAK || particle == PART_LIGHTNING ? 1 : partmul) / size / 30 * (elapse ? logf(elapse) / 3 : 1); num = max<int>(1, num); loopi(num) { vec ray = vec(dir).rotate(rnd(angle + 1) * RAD, axis).rotate(rnd(360), dir).mul(radius); switch(particle) { case PART_EXPLOSION: case PART_EXPLOSION_BLUE: ray.mul(rnd(101)/100.f).add(o); particle_fireball(ray, size, particle, fade, colour, size); break; case PART_STREAK: case PART_LIGHTNING: if(!curtime) return; particle_flare(o, ray.add(o), fade, particle, colour, size); break; default: ray.mul(rnd(101)/100.f).add(o); particle_splash(particle, 2, fade, ray, colour, size, max<int>(1, size * 2), gravity); break; } } }
void rpgent::tryattack(vec &lookatpos, rpgobj &weapon) { if(lastmillis-lastaction<weapon.s_attackrate) return; lastaction = lastmillis; switch(weapon.s_usetype) { case 1: if(!weapon.s_damage) return; weapon.usesound(this); loopallrpgobjsexcept(ro) tryattackobj(*eo, weapon); break; case 2: { if(!weapon.s_damage) return; weapon.usesound(this); particle_splash(PART_SPARK, 200, 250, lookatpos, 0xB49B4B, 0.24f); vec flarestart = o; flarestart.z -= 2; particle_flare(flarestart, lookatpos, 600, PART_STREAK, 0xFFC864, 0.28f); // FIXME hudgunorigin(), and shorten to maxrange float bestdist = 1e16f; rpgobj *best = NULL; loopallrpgobjsexcept(ro) { if(eo->ent->state!=CS_ALIVE) continue; if(!intersect(eo->ent, o, lookatpos)) continue; float dist = o.dist(eo->ent->o); if(dist<weapon.s_maxrange && dist<bestdist) { best = eo; bestdist = dist; } } if(best) weapon.useaction(*best, *this, true); break; } case 3: if(weapon.s_maxrange) // projectile, cast on target { if(magicprojectile) return; // only one in the air at once if(!ro->usemana(weapon)) return; magicprojectile = true; mpweapon = &weapon; mppos = o; //mpdir = vec(yaw*RAD, pitch*RAD); float worlddist = lookatpos.dist(o, mpdir); mpdir.normalize(); mpdist = min(float(weapon.s_maxrange), worlddist); } else { weapon.useaction(*ro, *this, true); // cast on self } break; } }
void effect::drawsplash(vec &o, vec dir, float radius, float size, int type, int elapse) { if(size <= 0) return; size *= this->size; int fade, gravity, num; setvars(this, type, fade, gravity, num); num *= .1 * radius / (1 + size) * partmul * (elapse ? logf(elapse) / 3 : 1); if(elapse && !num && rnd(int(10 / partmul))) return; //sometimes particles should not be drawn num = max(1, num); switch(particle) { case PART_EXPLOSION: case PART_EXPLOSION_BLUE: particle_fireball(o, radius ? radius : size, particle, fade, colour, size); break; case PART_STREAK: case PART_LIGHTNING: if(!curtime) break; if(!radius) //assume num == 1 { vec offset = vec(dir).mul(-2 * size).add(o); particle_flare(offset, o, fade, particle, colour, size); } else { num = (num / 2 + num % 2); loopi(num) { vec offset = vec(rnd(360) * RAD, (90 - rnd(180)) * RAD).mul(radius); vec offset2 = vec(rnd(360) * RAD, rnd(360) * RAD).mul(radius); particle_flare(vec(o).sub(offset), vec(o).add(offset2), fade, particle, colour, size); } } break; default: particle_splash(particle, num, fade, o, colour, size, max<int>(1, radius), gravity); break; } }
bool effect::drawline(vec &from, vec &to, float size, int type, int elapse) { if(size <= 0) return false; size *= this->size; int fade, gravity, num; setvars(this, type, fade, gravity, num); num *= from.dist(to) / (10 * size) * partmul * (elapse ? logf(elapse) / 3 : 1); if(particle == PART_STREAK || particle == PART_LIGHTNING) num /= 2; num = min<int>(min(num, linemaxsteps), from.dist(to) / linemininterval); if(!num) return false; vec delta = vec(to).sub(from).div(num); loopi(num) { switch(particle) { case PART_EXPLOSION: case PART_EXPLOSION_BLUE: particle_fireball(from, size * 2, particle, fade, colour, size * 2); break; case PART_STREAK: case PART_LIGHTNING: { if(!curtime) return false; vec start = vec(rnd(360) * RAD, rnd(360) * RAD).mul(4 * size).add(from); vec end = vec(delta).mul(1.5).add(start); particle_flare(start, end, fade, particle, colour, size); break; } default: particle_splash(particle, 2, fade, from, colour, size, max<int>(1, size * 5), gravity); break; } from.add(delta); } return true; }