16
Modding / ColisionRadius broken i think
« on: October 24, 2013, 09:23:25 AM »
nvrmind i figured it out... turn rate...
Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)
for (Iterator iter = directTargets.iterator(); iter.hasNext();)
[code]
the evil smiley gets into your code, eats your bits and leaves muddy footprints all over your classes
package data.scripts.EveryFrameCombatPlugin;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.CombatEntityAPI;
import com.fs.starfarer.api.combat.EveryFrameCombatPlugin;
import com.fs.starfarer.api.combat.MissileAPI;
import com.fs.starfarer.api.input.InputEventAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import org.lwjgl.util.vector.Vector2f;
import java.util.List;
import static org.lazywizard.lazylib.combat.CombatUtils.getShipsWithinRange;
public class Scatterb implements EveryFrameCombatPlugin {
private IntervalUtil tracker = new IntervalUtil(0.35f, 0.4f);
private static CombatEngineAPI activeEngine;
public void advance(float amount, MissileAPI missile, CombatEntityAPI target, CombatEngineAPI engine, java.lang.String SBKR1, List events) {
if (getShipsWithinRange(missile.getLocation(), 400f, true).get(0).isAlive())
{
target = getShipsWithinRange(missile.getLocation(), 400f, true).get(0);
{
//create variables
//capitalized can be changed
//insert targeter code here (anything goes, you may need to change it so T gives tx/ty a float value
//see at bottom for possible code
CombatEntityAPI T = target;//end point of " " (enemy api/point in space/ect) for targeter
MissileAPI P = missile; //start point of " " for weapon
float px = P.getLocation().getX(); //get location og p (for center of dakakakaka)
float py = P.getLocation().getY();
//float mvx = missile.getVelocity().getX();
//float mvy = missile.getVelocity().getY();
float tx = T.getLocation().getX(); //get location of t (for center of pew pew)
float ty = T.getLocation().getY();
double rxd = .5 - Math.random(); //generate a random double with -vs component, range -.5 to +.5
float rx = (float)rxd*2; // convert to float
double ryd = .5 - Math.random();
float ry = (float)ryd*2;
double rpd = Math.random(); //+ve random
float rp = (float)rpd;
float Tvar = 50f; //radius of t (sets mirv spread (angular))
float Pvar = 1f; //variable for vectors can use random float
double prany = py/Math.abs(py)*Pvar;
double pranx = px/Math.abs(px)*Pvar;
float prx = (float)pranx;
float pry = (float)prany;
float Rvar = 5f; //how much the velocities of projectiles can vary
double rvd = .5 - Math.random(); //generate random velocity multiplier for smooth function (to arr roughness back in
float rv = (float)rvd*Rvar;
//math
float Fx = (tx * rx * Tvar); //create randomized point field to shoot at
float Fy = (ty * ry * Tvar);
float Vx = (Fx * px * prx); //create vectors for pewpews to follow
float Vy = (Fy * py * pry);
double Smoothv = (Math.sqrt(((tx-px)*(tx-px))+((ty-py)*(ty-py)))/Math.sqrt((Vx*Vx)+(Vy*Vy)))*rv; //smoothes out ragged shot
float Sv = (float) Smoothv;
Vector2f Pjv = new Vector2f(Vx*Sv, Vy*Sv); //make the actual vector
engine.spawnProjectile(null, null,
SBKR1,
missile.getLocation(), 0,Pjv);
engine.removeEntity(missile); //make missile go poof
}
}
}
@Override
public void advance(float amount, List events) {
}
@Override
public void init(CombatEngineAPI engine) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
"behaviorSpec":{"behavior":"PROXIMITY_FUSE",
"range":3000,
"explosionSpec":{"duration":0.1f,
"radius":4000,
"coreRadius":3000, # full damage within core radius - also equal to proximity fuse range
"collisionClass":PROJECTILE_FF,
"collisionClassByFighter":PROJECTILE_FIGHTER,
"particleSizeMin":3.0,
"particleSizeRange":3.0,
"particleDuration":1,
"particleCount":100,
"particleColor":[255,40,40,255],
"sound":"explosion_flak"},
}
class cr/deployment cr recovery supplies per cr%
frigate, ~40%cr to deploy, 40%cr/day, 1 supplies/%
destroyer, ~30%cr to deploy, 20%cr/day, 2 supplies/%
cruiser, ~20%cr to deploy, 10%cr/day, 4 supplies/%
capital, ~10%cr to deploy, 5%cr/day, 8 supplies/%
public PluginPick<MissileAIPlugin> pickMissileAI(final MissileAPI missile, final ShipAPI launchingShip) {
if (missile.getWeapon() != null && missile.getWeapon().getId().equals("harpoon")) {
return new PluginPick<MissileAIPlugin>(new MissileAIPlugin() {
public void advance(float amount) {
missile.giveCommand(ShipCommand.TURN_RIGHT);
missile.giveCommand(ShipCommand.ACCELERATE);
}
}, PickPriority.MOD_GENERAL);
}
return null;
}
package data.scripts;
import com.fs.starfarer.api.BaseModPlugin;
import com.fs.starfarer.api.Global;
import data.scripts.world.BISOGen;
public class BISOModPlugin extends BaseModPlugin
{
private static void initBISO()
{
new BISOGen().generate(Global.getSector());
}
public PluginPick<MissileAIPlugin> pickMissileAI(final MissileAPI missile, final ShipAPI launchingShip) {
if (missile.getWeapon() != null && missile.getWeapon().getId().equals("harpoon")) {
return new PluginPick<MissileAIPlugin>(new MissileAIPlugin() {
public void advance(float amount) {
missile.giveCommand(ShipCommand.TURN_RIGHT);
missile.giveCommand(ShipCommand.ACCELERATE);
}
}, PickPriority.MOD_GENERAL);
}
return null;
}
@Override
public void onNewGame()
{
initBISO();
}
// the following code doesn't work right now, but it will in 0.6.1a!
// its stuff that will let you add it to existing saved games, rather than just new games
// @Override
// public void onEnabled(boolean wasEnabledBefore)
// {
// if (!wasEnabledBefore)
// {
// // Calling a separate method avoids duplicate code with onNewGame()
// initBISO();
// }
// }
}
@dmaiski: That should work. Are you perhaps expecting it to work on Harpoon Pods or the single-shot Harpoon launchers? That'll only work for 3-shot Harpoon racks, the ones with the weapon id "harpoon".
Aha - I'm not sure Janino actually supports anonymous classes, that might be it. You may need to extract the missile AI implementation into its own class.
public class BISOpickMissileAI extends pickMissileAI
{
public PluginPick<MissileAIPlugin> pickMissileAI(final MissileAPI missile, final ShipAPI launchingShip) {
if (missile.getWeapon() != null && missile.getWeapon().getId().equals("harpoon")) {
return new PluginPick<MissileAIPlugin>(new MissileAIPlugin() {
public void advance(float amount) {
missile.giveCommand(ShipCommand.TURN_RIGHT);
missile.giveCommand(ShipCommand.ACCELERATE);
}
}, PickPriority.MOD_GENERAL);
}
return null;
}
}
public class BISOpickMissileAI extends BaseModPlugin
{
public PluginPick<MissileAIPlugin> pickMissileAI(final MissileAPI missile, final ShipAPI launchingShip) {
if (missile.getWeapon() != null && missile.getWeapon().getId().equals("harpoon")) {
return new PluginPick<MissileAIPlugin>(new MissileAIPlugin() {
public void advance(float amount) {
missile.giveCommand(ShipCommand.TURN_RIGHT);
missile.giveCommand(ShipCommand.ACCELERATE);
}
}, PickPriority.MOD_GENERAL);
}
return null;
}
}
public class BISOpickMissileAI
{
public PluginPick<MissileAIPlugin> pickMissileAI(final MissileAPI missile, final ShipAPI launchingShip) {
if (missile.getWeapon() != null && missile.getWeapon().getId().equals("harpoon")) {
return new PluginPick<MissileAIPlugin>(new MissileAIPlugin() {
public void advance(float amount) {
missile.giveCommand(ShipCommand.TURN_RIGHT);
missile.giveCommand(ShipCommand.ACCELERATE);
}
}, PickPriority.MOD_GENERAL);
}
return null;
}
}
public class PluginPick<MissileAIPlugin> pickMissileAI(final MissileAPI missile, final ShipAPI launchingShip) {
if (missile.getWeapon() != null && missile.getWeapon().getId().equals("harpoon")) {
return new PluginPick<MissileAIPlugin>(new MissileAIPlugin() {
public void advance(float amount) {
missile.giveCommand(ShipCommand.TURN_RIGHT);
missile.giveCommand(ShipCommand.ACCELERATE);
}
}, PickPriority.MOD_GENERAL);
}
return null;
}
36844 [Thread-6] INFO com.fs.graphics.TextureLoader - Cleaned buffer for texture graphics/biso/ships/D1.png (using cast)
36844 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loading [graphics/ships/phase/phase_strike_ff.png] as texture with id [graphics/ships/phase/phase_strike_ff.png]
36860 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loaded 160.49 MB of texture data so far
36860 [Thread-6] INFO com.fs.graphics.TextureLoader - Cleaned buffer for texture graphics/ships/phase/phase_strike_ff.png (using cast)
36860 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loading [graphics/ships/medusa.png] as texture with id [graphics/ships/medusa.png]
36891 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loaded 160.82 MB of texture data so far
36891 [Thread-6] INFO com.fs.graphics.TextureLoader - Cleaned buffer for texture graphics/ships/medusa.png (using cast)
36891 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loading [graphics/ships/buffalo_dd.png] as texture with id [graphics/ships/buffalo_dd.png]
36922 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loaded 160.98 MB of texture data so far
36922 [Thread-6] INFO com.fs.graphics.TextureLoader - Cleaned buffer for texture graphics/ships/buffalo_dd.png (using cast)
36922 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loading [graphics/ships/atlas_af.png] as texture with id [graphics/ships/atlas_af.png]
36985 [Thread-6] DEBUG com.fs.graphics.TextureLoader - Loaded 161.65 MB of texture data so far
36985 [Thread-6] INFO com.fs.graphics.TextureLoader - Cleaned buffer for texture graphics/ships/atlas_af.png (using cast)
37110 [Thread-6] INFO com.fs.profiler.Profiler - ID Calls Duration Percent
37110 [Thread-6] INFO com.fs.profiler.Profiler - --------------------------------------------------
37110 [Thread-6] INFO com.fs.profiler.Profiler - Resource loading 1 23.89s 100.00%
37156 [Thread-6] ERROR com.fs.starfarer.combat.String - java.lang.RuntimeException: Error compiling [data.scripts.BISOModPlugin]
java.lang.RuntimeException: Error compiling [data.scripts.BISOModPlugin]
at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: Parsing compilation unit "com.fs.starfarer.loading.A$1@670479"
at org.codehaus.janino.JavaSourceIClassLoader.findIClass(JavaSourceIClassLoader.java:180)
at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:158)
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:199)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:164)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: File data/scripts/BISOModPlugin.java, Line 14, Column 6: Expression "new MissileAI()" is not a type
at org.codehaus.janino.Java$Located.throwCompileException(Java.java:97)
at org.codehaus.janino.Java$Atom.toTypeOrPE(Java.java:1899)
at org.codehaus.janino.Parser.parseBlockStatement(Parser.java:1010)
at org.codehaus.janino.Parser.parseBlockStatements(Parser.java:938)
at org.codehaus.janino.Parser.parseMethodDeclarationRest(Parser.java:804)
at org.codehaus.janino.Parser.parseClassBodyDeclaration(Parser.java:442)
at org.codehaus.janino.Parser.parseClassBody(Parser.java:393)
at org.codehaus.janino.Parser.parseClassDeclarationRest(Parser.java:372)
at org.codehaus.janino.Parser.parsePackageMemberTypeDeclaration(Parser.java:251)
at org.codehaus.janino.Parser.parseCompilationUnit(Parser.java:153)
at org.codehaus.janino.JavaSourceIClassLoader.findIClass(JavaSourceIClassLoader.java:150)
... 7 more