Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Parsing Compilation Unit: Hullmod  (Read 3980 times)

Protonus

  • Captain
  • ****
  • Posts: 444
  • AAAAAAAAAAAA
    • View Profile
Parsing Compilation Unit: Hullmod
« on: January 14, 2015, 06:08:44 AM »

Well, I'm kinda shy asking the forums themselves for information that I need to get stuff done, but I'm starting to get a little bothered with this error I got, despite of having Netbeans to work with the hullmod.

I received after adding the hullmod into my... mod.

This is what I get:
Fatal: Error compiling [data.hullmods.pt_centuriondrive]
Cause: Parsing compilation unit "com.fs.starfarer.loading.A$1@1a7e777"

I tried using two separate numeral techniques for the Zero Flux attribute but it doesn't to work for some reason.
This is the code I have.
Spoiler
Quote
package data.hullmods;

import java.util.HashMap;
import java.util.Map;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;

public class PT_CenturionDrive extends BaseHullMod {

   public static final float EMP_REDUCTION = 25f;
   public static final float ENGINE_HEALTH_BONUS = 125f;
//   public static final float ZERO_FLUX_SPEED_CAPITAL = 15f;
//   public static final float ZERO_FLUX_SPEED_CRUISER = 20f;
//   public static final float ZERO_FLUX_SPEED_DESTROYER = 25f;
//   public static final float ZERO_FLUX_SPEED_FRIGATE = 35f;
//   public static final float ZERO_FLUX_BONUS_CAPITAL = 0.05f;
//   public static final float ZERO_FLUX_BONUS_CRUISER = 0.1f;
//   public static final float ZERO_FLUX_BONUS_DESTROYER = 0.15f;
//   public static final float ZERO_FLUX_BONUS_FRIGATE = 0.2f;
   public static final float WEAPON_HEALTH_BONUS = 75f;

   private static final Map ZeroFluxBonus = new HashMap();
   static {
      ZeroFluxBonus.put(HullSize.FRIGATE, 0.2f);
      ZeroFluxBonus.put(HullSize.DESTROYER, 0.15f);
      ZeroFluxBonus.put(HullSize.CRUISER, 0.1f);
      ZeroFluxBonus.put(HullSize.CAPITAL_SHIP, 0.05f);
   }
   
   private static final Map ZeroFluxSpeed = new HashMap();
   static {
      ZeroFluxSpeed.put(HullSize.FRIGATE, 35f);
      ZeroFluxSpeed.put(HullSize.DESTROYER, 25f);
      ZeroFluxSpeed.put(HullSize.CRUISER, 20f);
      ZeroFluxSpeed.put(HullSize.CAPITAL_SHIP, 15f);
   }
   
    @Override
    public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
        
      stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, (Float) ZeroFluxBonus.get(hullSize));
      stats.getZeroFluxSpeedBoost().modifyFlat(id, (Float) ZeroFluxSpeed.get(hullSize));
//      if (hullSize == HullSize.FRIGATE || hullSize == HullSize.FIGHTER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_FRIGATE);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_FRIGATE);
//      } else if (hullSize == HullSize.DESTROYER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_DESTROYER);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_DESTROYER);
//      } else if (hullSize == HullSize.CRUISER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_CRUISER);
//         stats.getZeroFluxSpeedBoost().modifyPercent(id, ZERO_FLUX_SPEED_CRUISER);
//      } else if (hullSize == HullSize.CAPITAL_SHIP) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_CAPITAL);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_CAPITAL);
//      }
      stats.getEmpDamageTakenMult().modifyPercent(id, -EMP_REDUCTION);
      stats.getEngineHealthBonus().modifyPercent(id, ENGINE_HEALTH_BONUS);
      stats.getWeaponHealthBonus().modifyPercent(id, WEAPON_HEALTH_BONUS);
    }

    @Override
    public String getDescriptionParam(int index, HullSize hullSize) {
      if (index == 0) return "" + ((Float) ZeroFluxBonus.get(HullSize.FRIGATE)).intValue();
      if (index == 1) return "" + ((Float) ZeroFluxBonus.get(HullSize.DESTROYER)).intValue();
      if (index == 2) return "" + ((Float) ZeroFluxBonus.get(HullSize.CRUISER)).intValue();
      if (index == 3) return "" + ((Float) ZeroFluxBonus.get(HullSize.CAPITAL_SHIP)).intValue();
      
      if (index == 4) return "" + ((Float) ZeroFluxSpeed.get(HullSize.FRIGATE)).intValue();
      if (index == 5) return "" + ((Float) ZeroFluxSpeed.get(HullSize.DESTROYER)).intValue();
      if (index == 6) return "" + ((Float) ZeroFluxSpeed.get(HullSize.CRUISER)).intValue();
      if (index == 7) return "" + ((Float) ZeroFluxSpeed.get(HullSize.CAPITAL_SHIP)).intValue();
      
//      if (index == 0) {
//         return "" + (int) ZERO_FLUX_BONUS_FRIGATE + "/" + (int) ZERO_FLUX_BONUS_DESTROYER + "/" + (int) ZERO_FLUX_BONUS_CRUISER + "/" + (int) ZERO_FLUX_BONUS_CAPITAL;
//      } if (index == 1) {
//         return "" + (int) ZERO_FLUX_SPEED_FRIGATE + "/" + (int) ZERO_FLUX_SPEED_DESTROYER + "/" + (int) ZERO_FLUX_SPEED_CRUISER + "/" + (int) ZERO_FLUX_SPEED_CAPITAL;
      if (index == 8) return "" + (int) EMP_REDUCTION + "%";
      if (index == 9) return "" + (int) ENGINE_HEALTH_BONUS + "%";
      if (index == 10) return "" + (int) WEAPON_HEALTH_BONUS + "%";
      return null;
    }
}
[close]

So, yeah.


Edit: I didn't expect the Emoticon to pop out of the index.
Logged

The cookies are a weird one, okay.

kazi

  • Admiral
  • *****
  • Posts: 714
    • View Profile
Re: Parsing Compilation Unit: Hullmod
« Reply #1 on: January 14, 2015, 10:46:36 PM »

You should post the stacktrace. It will help you identify where the error is.

You may also want to change the if statments to something along the lines of:
Code
if (hullSize.equals(HullSize.CRUISER)) {}
instead of:
Code
if (hullSize == HullSize.CRUISER) {}

Typically you want to use ".equals()" to test for enum and object equivalence rather than "==". "==" just compares the object reference, not the object itself. I think.  :P
Logged

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2806
    • View Profile
    • Sc2Mafia
Re: Parsing Compilation Unit: Hullmod
« Reply #2 on: January 14, 2015, 11:06:33 PM »

It doesn't matter for enums, actually, since they're sort of like static variables (i.e. can't be instantiated other than by listing more names in the enum definition).  If it's not overridden, I believe the Object.equals(Object) function behaves exactly like Object == Object, except it's slightly slower because it's a function call, and in this case it can throw a NPE if the first enum is null.
« Last Edit: January 14, 2015, 11:08:37 PM by Dark.Revenant »
Logged

Protonus

  • Captain
  • ****
  • Posts: 444
  • AAAAAAAAAAAA
    • View Profile
Re: Parsing Compilation Unit: Hullmod
« Reply #3 on: January 18, 2015, 04:20:33 PM »

I still didn't how the scripting didn't actually work even though it is logically correct.

Do you think it requires some files in order to make the Java script coding to be readable?
Logged

The cookies are a weird one, okay.

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: Parsing Compilation Unit: Hullmod
« Reply #4 on: January 18, 2015, 05:19:58 PM »

Well, I'm kinda shy asking the forums themselves for information that I need to get stuff done, but I'm starting to get a little bothered with this error I got, despite of having Netbeans to work with the hullmod.

I received after adding the hullmod into my... mod.

This is what I get:
Fatal: Error compiling [data.hullmods.pt_centuriondrive]
Cause: Parsing compilation unit "com.fs.starfarer.loading.A$1@1a7e777"

I tried using two separate numeral techniques for the Zero Flux attribute but it doesn't to work for some reason.
This is the code I have.
Spoiler
Quote
package data.hullmods;

import java.util.HashMap;
import java.util.Map;

import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;

public class PT_CenturionDrive extends BaseHullMod {

   public static final float EMP_REDUCTION = 25f;
   public static final float ENGINE_HEALTH_BONUS = 125f;
//   public static final float ZERO_FLUX_SPEED_CAPITAL = 15f;
//   public static final float ZERO_FLUX_SPEED_CRUISER = 20f;
//   public static final float ZERO_FLUX_SPEED_DESTROYER = 25f;
//   public static final float ZERO_FLUX_SPEED_FRIGATE = 35f;
//   public static final float ZERO_FLUX_BONUS_CAPITAL = 0.05f;
//   public static final float ZERO_FLUX_BONUS_CRUISER = 0.1f;
//   public static final float ZERO_FLUX_BONUS_DESTROYER = 0.15f;
//   public static final float ZERO_FLUX_BONUS_FRIGATE = 0.2f;
   public static final float WEAPON_HEALTH_BONUS = 75f;

   private static final Map ZeroFluxBonus = new HashMap();
   static {
      ZeroFluxBonus.put(HullSize.FRIGATE, 0.2f);
      ZeroFluxBonus.put(HullSize.DESTROYER, 0.15f);
      ZeroFluxBonus.put(HullSize.CRUISER, 0.1f);
      ZeroFluxBonus.put(HullSize.CAPITAL_SHIP, 0.05f);
   }
   
   private static final Map ZeroFluxSpeed = new HashMap();
   static {
      ZeroFluxSpeed.put(HullSize.FRIGATE, 35f);
      ZeroFluxSpeed.put(HullSize.DESTROYER, 25f);
      ZeroFluxSpeed.put(HullSize.CRUISER, 20f);
      ZeroFluxSpeed.put(HullSize.CAPITAL_SHIP, 15f);
   }
   
    @Override
    public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
        
      stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, (Float) ZeroFluxBonus.get(hullSize));
      stats.getZeroFluxSpeedBoost().modifyFlat(id, (Float) ZeroFluxSpeed.get(hullSize));
//      if (hullSize == HullSize.FRIGATE || hullSize == HullSize.FIGHTER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_FRIGATE);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_FRIGATE);
//      } else if (hullSize == HullSize.DESTROYER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_DESTROYER);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_DESTROYER);
//      } else if (hullSize == HullSize.CRUISER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_CRUISER);
//         stats.getZeroFluxSpeedBoost().modifyPercent(id, ZERO_FLUX_SPEED_CRUISER);
//      } else if (hullSize == HullSize.CAPITAL_SHIP) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_CAPITAL);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_CAPITAL);
//      }
      stats.getEmpDamageTakenMult().modifyPercent(id, -EMP_REDUCTION);
      stats.getEngineHealthBonus().modifyPercent(id, ENGINE_HEALTH_BONUS);
      stats.getWeaponHealthBonus().modifyPercent(id, WEAPON_HEALTH_BONUS);
    }

    @Override
    public String getDescriptionParam(int index, HullSize hullSize) {
      if (index == 0) return "" + ((Float) ZeroFluxBonus.get(HullSize.FRIGATE)).intValue();
      if (index == 1) return "" + ((Float) ZeroFluxBonus.get(HullSize.DESTROYER)).intValue();
      if (index == 2) return "" + ((Float) ZeroFluxBonus.get(HullSize.CRUISER)).intValue();
      if (index == 3) return "" + ((Float) ZeroFluxBonus.get(HullSize.CAPITAL_SHIP)).intValue();
      
      if (index == 4) return "" + ((Float) ZeroFluxSpeed.get(HullSize.FRIGATE)).intValue();
      if (index == 5) return "" + ((Float) ZeroFluxSpeed.get(HullSize.DESTROYER)).intValue();
      if (index == 6) return "" + ((Float) ZeroFluxSpeed.get(HullSize.CRUISER)).intValue();
      if (index == 7) return "" + ((Float) ZeroFluxSpeed.get(HullSize.CAPITAL_SHIP)).intValue();
      
//      if (index == 0) {
//         return "" + (int) ZERO_FLUX_BONUS_FRIGATE + "/" + (int) ZERO_FLUX_BONUS_DESTROYER + "/" + (int) ZERO_FLUX_BONUS_CRUISER + "/" + (int) ZERO_FLUX_BONUS_CAPITAL;
//      } if (index == 1) {
//         return "" + (int) ZERO_FLUX_SPEED_FRIGATE + "/" + (int) ZERO_FLUX_SPEED_DESTROYER + "/" + (int) ZERO_FLUX_SPEED_CRUISER + "/" + (int) ZERO_FLUX_SPEED_CAPITAL;
      if (index == 8) return "" + (int) EMP_REDUCTION + "%";
      if (index == 9) return "" + (int) ENGINE_HEALTH_BONUS + "%";
      if (index == 10) return "" + (int) WEAPON_HEALTH_BONUS + "%";
      return null;
    }
}
[close]

So, yeah.


Edit: I didn't expect the Emoticon to pop out of the index.

Not sure if it was an artifact of copy/pasting through these forums, but there were a number of illegal white space characters in your source. (no-break spaces)
Logged

Protonus

  • Captain
  • ****
  • Posts: 444
  • AAAAAAAAAAAA
    • View Profile
Re: Parsing Compilation Unit: Hullmod
« Reply #5 on: January 23, 2015, 10:49:12 PM »

Not sure if it was an artifact of copy/pasting through these forums, but there were a number of illegal white space characters in your source. (no-break spaces)

I managed to remove the Non-break spaces you told me, but the game still rejects the Java coding.

This is the error info:
Fatal: Error compiling [data.hullmods.pt_centuriondrive]
Cause: Parsing compilation unit "com.fs.starfarer.loading.A$1@1944F0c"


This is the coding I used now:
Spoiler
Quote
package data.hullmods.pt_centuriondrive;
import java.util.HashMap;
import java.util.Map;
import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.ShipAPI.HullSize;

public class PT_CenturionDrive extends BaseHullMod {

 public static final float EMP_REDUCTION = 25f;
   public static final float ENGINE_HEALTH_BONUS = 125f;
//   public static final float ZERO_FLUX_SPEED_CAPITAL = 15f;
//   public static final float ZERO_FLUX_SPEED_CRUISER = 20f;
//   public static final float ZERO_FLUX_SPEED_DESTROYER = 25f;
//   public static final float ZERO_FLUX_SPEED_FRIGATE = 35f;
//   public static final float ZERO_FLUX_BONUS_CAPITAL = 0.05f;
//   public static final float ZERO_FLUX_BONUS_CRUISER = 0.1f;
//   public static final float ZERO_FLUX_BONUS_DESTROYER = 0.15f;
//   public static final float ZERO_FLUX_BONUS_FRIGATE = 0.2f;
   public static final float WEAPON_HEALTH_BONUS = 75f;

   private static final Map ZeroFluxBonus = new HashMap();
   static {
      ZeroFluxBonus.put(HullSize.FRIGATE, 0.2f);
      ZeroFluxBonus.put(HullSize.DESTROYER, 0.15f);
      ZeroFluxBonus.put(HullSize.CRUISER, 0.1f);
      ZeroFluxBonus.put(HullSize.CAPITAL_SHIP, 0.05f);
   }
   
   private static final Map ZeroFluxSpeed = new HashMap();
   static {
      ZeroFluxSpeed.put(HullSize.FRIGATE, 35f);
      ZeroFluxSpeed.put(HullSize.DESTROYER, 25f);
      ZeroFluxSpeed.put(HullSize.CRUISER, 20f);
      ZeroFluxSpeed.put(HullSize.CAPITAL_SHIP, 15f);
   }
   
   @Override
   public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
      
//      stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, (Float) ZeroFluxBonus.get(hullSize));
//      stats.getZeroFluxSpeedBoost().modifyFlat(id, (Float) ZeroFluxSpeed.get(hullSize));
//      if (hullSize == HullSize.FRIGATE || hullSize == HullSize.FIGHTER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_FRIGATE);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_FRIGATE);
//      } else if (hullSize == HullSize.DESTROYER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_DESTROYER);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_DESTROYER);
//      } else if (hullSize == HullSize.CRUISER) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_CRUISER);
//         stats.getZeroFluxSpeedBoost().modifyPercent(id, ZERO_FLUX_SPEED_CRUISER);
//      } else if (hullSize == HullSize.CAPITAL_SHIP) {
//         stats.getZeroFluxMinimumFluxLevel().modifyFlat(id, ZERO_FLUX_BONUS_CAPITAL);
//         stats.getZeroFluxSpeedBoost().modifyFlat(id, ZERO_FLUX_SPEED_CAPITAL);
//      }
      stats.getEmpDamageTakenMult().modifyPercent(id, -EMP_REDUCTION);
      stats.getEngineHealthBonus().modifyPercent(id, ENGINE_HEALTH_BONUS);
      stats.getWeaponHealthBonus().modifyPercent(id, WEAPON_HEALTH_BONUS);
    }

    @Override
    public String getDescriptionParam(int index, HullSize hullSize) {
      if (index == 0) return "" + (int) EMP_REDUCTION + "%";
      if (index == 1) return "" + (int) ENGINE_HEALTH_BONUS + "%";
      if (index == 2) return "" + (int) WEAPON_HEALTH_BONUS + "%";
//      if (index == 0) return "" + ((int) ZeroFluxBonus.get(HullSize.FRIGATE)).intValue();
//      if (index == 1) return "" + ((int) ZeroFluxBonus.get(HullSize.DESTROYER)).intValue();
//      if (index == 2) return "" + ((int) ZeroFluxBonus.get(HullSize.CRUISER)).intValue();
//      if (index == 3) return "" + ((int) ZeroFluxBonus.get(HullSize.CAPITAL_SHIP)).intValue();
      
//      if (index == 4) return "" + ((int) ZeroFluxSpeed.get(HullSize.FRIGATE)).intValue();
//      if (index == 5) return "" + ((int) ZeroFluxSpeed.get(HullSize.DESTROYER)).intValue();
//      if (index == 6) return "" + ((int) ZeroFluxSpeed.get(HullSize.CRUISER)).intValue();
//      if (index == 7) return "" + ((int) ZeroFluxSpeed.get(HullSize.CAPITAL_SHIP)).intValue();
      
//      if (index == 0) {
//         return "" + (int) ZERO_FLUX_BONUS_FRIGATE + "/" + (int) ZERO_FLUX_BONUS_DESTROYER + "/" + (int) ZERO_FLUX_BONUS_CRUISER + "/" + (int) ZERO_FLUX_BONUS_CAPITAL;
//      } if (index == 1) {
//         return "" + (int) ZERO_FLUX_SPEED_FRIGATE + "/" + (int) ZERO_FLUX_SPEED_DESTROYER + "/" + (int) ZERO_FLUX_SPEED_CRUISER + "/" + (int) ZERO_FLUX_SPEED_CAPITAL;
//      if (index == 8) return "" + (int) EMP_REDUCTION + "%";
//      if (index == 9) return "" + (int) ENGINE_HEALTH_BONUS + "%";
//      if (index == 10) return "" + (int) WEAPON_HEALTH_BONUS + "%";
      return null;
    }
}
[close]

Does that mean I should use a .class file of the code? Or is the coding I made is still wrong?

If the first is "yes", then how should I actually make a .class code that compliments the .Java file and which programs I should use?

I do see a lot of mods using .class files for their scripting.
Logged

The cookies are a weird one, okay.

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: Parsing Compilation Unit: Hullmod
« Reply #6 on: January 24, 2015, 02:57:15 AM »

Syntax-wise your code is fine.

Suggestions:
1) You're using annotations ("@Override"); does the version of janino currently being used by Starfarer support them?
2) Does the file name of the .java file precisely match the class name? (the error message "data.hullmods.pt_centuriondrive" suggests that the case might be wrong)
Logged

Protonus

  • Captain
  • ****
  • Posts: 444
  • AAAAAAAAAAAA
    • View Profile
Re: Parsing Compilation Unit: Hullmod
« Reply #7 on: January 24, 2015, 06:53:52 AM »

Syntax-wise your code is fine.

Suggestions:
1) You're using annotations ("@Override"); does the version of janino currently being used by Starfarer support them?
2) Does the file name of the .java file precisely match the class name? (the error message "data.hullmods.pt_centuriondrive" suggests that the case might be wrong)

1. I did the code with and without @Override annotation, the results end up the same.
2. Yes. I did the Java name precisely with the Class name. (Copy-pasted it even.)
Logged

The cookies are a weird one, okay.

Protonus

  • Captain
  • ****
  • Posts: 444
  • AAAAAAAAAAAA
    • View Profile
Re: Parsing Compilation Unit: Hullmod
« Reply #8 on: January 26, 2015, 06:36:03 AM »

My mistake.

I think it has something to do with the Excel coding. Managed to fix it now.

Thanks for the help, though. And sorry about the confusion I made. ???
Logged

The cookies are a weird one, okay.