001package com.fs.starfarer.api.impl.campaign.terrain; 002 003import org.lwjgl.util.vector.Vector2f; 004 005import com.fs.starfarer.api.EveryFrameScript; 006import com.fs.starfarer.api.Global; 007import com.fs.starfarer.api.campaign.CampaignFleetAPI; 008import com.fs.starfarer.api.util.Misc; 009 010public class ShoveFleetScript implements EveryFrameScript { 011 012 public static float IMPACT_SPEED_DELTA = Global.getSettings().getSpeedPerBurnLevel(); 013 public static float DURATION_SECONDS = 0.1f; 014 015 protected CampaignFleetAPI fleet; 016 protected float elapsed; 017 protected float angle; 018 protected float intensity; 019 protected float impact = IMPACT_SPEED_DELTA; 020 protected Vector2f dV; 021 022 public ShoveFleetScript(CampaignFleetAPI fleet, float direction, float intensity) { 023 this.fleet = fleet; 024 this.intensity = intensity; 025 this.angle = direction; 026 027 //DURATION_SECONDS = 0.1f; 028 029 dV = Misc.getUnitVectorAtDegreeAngle(angle); 030 031 float fleetWeightFactor = (float) fleet.getFleetPoints() / 200f; 032 if (fleetWeightFactor > 1f) fleetWeightFactor = 1f; 033 fleetWeightFactor = 0.5f + 1f * (1f - fleetWeightFactor); 034 035 float speed = IMPACT_SPEED_DELTA * 40f * intensity; 036 float impact = speed * 1f * fleetWeightFactor; 037 dV.scale(impact); 038 dV.scale(1f / DURATION_SECONDS); 039 } 040 041 public void advance(float amount) { 042 043 fleet.setOrbit(null); 044 045 Vector2f v = fleet.getVelocity(); 046 fleet.setVelocity(v.x + dV.x * amount, v.y + dV.y * amount); 047 048// Vector2f dir = Misc.getUnitVectorAtDegreeAngle(angle); 049// 050// float fleetWeightFactor = (float) fleet.getFleetPoints() / 200f; 051// if (fleetWeightFactor > 1f) fleetWeightFactor = 1f; 052// fleetWeightFactor = 0.5f + 1f * (1f - fleetWeightFactor); 053// 054// dir.scale(IMPACT_SPEED_DELTA * intensity * fleetWeightFactor* amount * 055// (Math.min(20f, Math.max(10f, fleet.getCurrBurnLevel())) * 50f) * (0.5f + (float) Math.random() * 0.5f)); 056// 057// Vector2f v = fleet.getVelocity(); 058// fleet.setVelocity(v.x + dir.x, v.y + dir.y); 059 060 elapsed += amount; 061 062 } 063 064 public boolean isDone() { 065 return elapsed >= DURATION_SECONDS; 066 } 067 068 public boolean runWhilePaused() { 069 return false; 070 } 071 072}