void EarthlingCruiserMk3::calculate() { STACKTRACE; Ship::calculate(); double track_angle = 0; double track_min = PI2; double d_a; SpaceObject *tgt = 0; //!!! pos += unit_vector(angle) * 28; int i; for (i=0; i < targets->N; i++) { tgt = targets->item[i]; if ((tgt != this) && (!tgt->sameShip(this)) && (!tgt->sameTeam(this)) && (!tgt->isInvisible()) && (distance(tgt) <= 1.2*(weaponRange + abs(vel)*game->shot_relativity))) { d_a = trajectory_angle(tgt); double s = unit_vector(d_a + PI/2).dot(tgt->get_vel() - vel * game->shot_relativity) / weaponVelocity; if (fabs(s) > 0.99) track_angle = 0; else { s = atan(s/sqrt(1-s*s)); s = normalize(s + d_a - angle - turn_step, PI2); if (s > PI) s -= PI2; if (fabs(s) <= weaponTrackingAngle) { d_a = s - launch_angle; if (tgt == target) { track_angle = s; break; } if (fabs(d_a) < track_min) { track_angle = s; track_min = fabs(d_a); } } } } } //!!! pos -= unit_vector(angle) * 28; d_a = track_angle - launch_angle; double ta = weaponTrackingRate * frame_time; if (fabs(d_a) < ta) ta = fabs(d_a); if (d_a > 0) launch_angle += ta; else launch_angle -= ta; }
void AstromorphBasilisk::calculate() { STACKTRACE; // firing the weapon // vel*=0.99; if (aimline && !fire_weapon && batt - weapon_drain >= 0 && weapon_recharge <= 0) { play_sound2(data->sampleWeapon[1]); batt -= weapon_drain; if (recharge_amount > 1) recharge_step = recharge_rate; weapon_recharge += weapon_rate; regrow_delay = regrowTime; double a; if (aimline->target != NULL) { SpaceObject* targ = aimline->target; a = intercept_angle2(pos, vel * game->shot_relativity, weaponVelocity*aimBonus, targ->normal_pos(), targ->get_vel()); } else a = angle; add(new BasiliskGas(0.0, 0.0, a, (aimline->target != NULL) ? weaponVelocity*aimBonus : weaponVelocity, weaponDamage, weaponLife, weaponRange, iround(weaponArmour), poison, this, data->spriteWeapon, 1.0)); aimline->target = NULL; aimline = NULL; } // slithering //if (!(turn_left || turn_right || !thrust)) { //double frac = float(numSegs)/float(specialSegs); //double frac2 = numSegs/specialSegs; //double frac2 = magnitude(this->vel)/speed_max; double frac2 = 1.0; Vector2 normal; normal = Vector2(-vel.y, vel.x); normalize(normal); slitherFrame += frame_time * 1E-3; double a; //a = sin(PI * (frac2)*slitherFrame / 1.0 + (PI/2) ) *( (frac)*slitherAmount); // needs some work! a = (slitherAmount)*sin(slitherFrame * (frac2*slitherTime)/(PI/2) ); vel += (accel_rate*frame_time) * a * normal; /* slitherFrame -= frame_time; slitherTick += frame_time * slitherAmount; frac2 = sin(slitherTick); slitherFrame *= frac;*/ //if (slitherFrame < 0) //{ // slitherFrame = slitherTime; // bOtherWay = !bOtherWay; //} //angle -= (bOtherWay) ? (PI2/64) : -(PI2/64); /*accelerate(this, //normalize(angle - ((bOtherWay) ? (PI/4) : -(PI/4)), PI2), normalize(angle - (frac2*(PI/4))), slitherAccel*frac*frame_time, speed_max);*/ } // else { //slitherFrame = slitherTime/2; //bOtherWay = turn_right; } Ship::calculate(); // ouchification tickdown if (hurty_time <= 0) vel *= 1 - slitherFriction * frame_time; if (hurty_time >= 0) hurty_time -= frame_time * 1E-3; if (hurty_time < 0) hurty_time = 0; // regrowth if (batt == batt_max && regrowTime > 0) { regrow_delay -= frame_time * 1E-3; if (regrow_delay <= 0) if (Head) if (Head->regrow(specialSegs)) { batt -= regrowDrain; regrow_delay = regrowTime; } } }