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: Faction Spawn Points  (Read 6319 times)

MiniFishy

  • Ensign
  • *
  • Posts: 32
    • View Profile
Faction Spawn Points
« on: June 12, 2012, 05:28:15 PM »

I've looked at the two tutorials by Paul but I continue to get the same error; A compiling error by my FishyGen.java file. It is always the same line and word, but no matter what I enter it does not work.
Now I've been modifying and mangling this code probably beyond recognition for over an hour now as I am not too experienced with this sort of coding.

I was hoping you guys could help me find the problem and fix it, I am too tired to carry on now.

Starfarer.log
Spoiler
java.lang.RuntimeException: Error compiling [data.scripts.world.FishyGen]
   at com.fs.starfarer.loading.scripts.ScriptStore$1.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: Compiling unit "data/scripts/world/FishyGen.java"
   at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:205)
   at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:157)
   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/world/FishyGen.java, Line 25, Column 56: Unknown variable or type "CorvusIV"
   at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:9014)
   at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:4685)
   at org.codehaus.janino.UnitCompiler.access$10000(UnitCompiler.java:104)
   at org.codehaus.janino.UnitCompiler$17.visitPackage(UnitCompiler.java:4438)
   at org.codehaus.janino.Java$Package.accept(Java.java:2231)
   at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:4476)
   at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:4682)
   at org.codehaus.janino.UnitCompiler.access$12500(UnitCompiler.java:104)
   at org.codehaus.janino.UnitCompiler$17.visitAmbiguousName(UnitCompiler.java:4466)
   at org.codehaus.janino.Java$AmbiguousName.accept(Java.java:2216)
   at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:4476)
   at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:6688)
   at org.codehaus.janino.UnitCompiler.invokeConstructor(UnitCompiler.java:5695)
   at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3673)
   at org.codehaus.janino.UnitCompiler.access$6900(UnitCompiler.java:104)
   at org.codehaus.janino.UnitCompiler$11.visitNewClassInstance(UnitCompiler.java:2875)
   at org.codehaus.janino.Java$NewClassInstance.accept(Java.java:2922)
   at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2890)
   at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3897)
   at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3503)
   at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:104)
   at org.codehaus.janino.UnitCompiler$11.visitMethodInvocation(UnitCompiler.java:2869)
   at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2831)
   at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2890)
   at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3897)
   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2326)
   at org.codehaus.janino.UnitCompiler.access$3800(UnitCompiler.java:104)
   at org.codehaus.janino.UnitCompiler$8.visitMethodInvocation(UnitCompiler.java:2299)
   at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2831)
   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:2320)
   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1353)
   at org.codehaus.janino.UnitCompiler.access$800(UnitCompiler.java:104)
   at org.codehaus.janino.UnitCompiler$5.visitExpressionStatement(UnitCompiler.java:868)
   at org.codehaus.janino.Java$ExpressionStatement.accept(Java.java:1457)
   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:888)
   at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:914)
   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1999)
   at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:789)
   at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:770)
   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:464)
   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:357)
   at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:312)
   at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:770)
   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:319)
   at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:288)
   at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:203)
   ... 5 more





[close]

FishyGen.java
Spoiler
package data.scripts.world;

import java.awt.Color;
import java.util.List;

import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.CargoAPI;
import com.fs.starfarer.api.campaign.FactionAPI;
import com.fs.starfarer.api.campaign.FleetAssignment;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.SectorGeneratorPlugin;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;
import com.fs.starfarer.api.fleet.FleetMemberType;

@SuppressWarnings("unchecked")
public class FishyGen extends SectorGen {

   public void generate(SectorAPI sector) {
  
    StarSystemAPI system = sector.getStarSystem("Corvus");

SectorEntityToken token = system.createToken(15000, 0);  
    system.addSpawnPoint(new UnknownSpawnPoint(CorvusIV, 45, 30, 1, token));
token = system.createToken(15000, -15000);
      system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 14, 1, token, station2));
      
      FactionAPI unknown = sector.getFaction("unknown");
      
      unknown.setRelationship("hegemony", -1);
      unknown.setRelationship("tritachyon", -1);
      unknown.setRelationship("pirates", 0);
      unknown.setRelationship("independent", 0);
    unknown.setRelationship("player", 0);
   }
   }



[close]

UnknownSpawnPoint.java
Spoiler
package data.scripts.world;

import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.FleetAssignment;
import com.fs.starfarer.api.campaign.LocationAPI;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;

import data.scripts.world.BaseSpawnPoint;

public class UnknownSpawnPoint extends BaseSpawnPoint {

   private final SectorEntityToken station;

   public UnknownSpawnPoint(SectorAPI sector, LocationAPI location,
                     float daysInterval, int maxFleets, SectorEntityToken anchor,
                     SectorEntityToken station) {
      super(sector, location, daysInterval, maxFleets, anchor);
      this.station = station;
   }

   @Override
   protected CampaignFleetAPI spawnFleet() {
      //if ((float) Math.random() < 0.5f) return null;
      
      String type = null;
      float r = (float) Math.random();
      if (r > .8f) {
         type = "scout";
      } else if (r > 0.5f) {
         type = "raiders";
      } else if (r > 0.2f) {
         type = "attackFleet";
      } else {
         type = "securityDetachment";
      }
      
      CampaignFleetAPI fleet = getSector().createFleet("tritachyon", type);
      getLocation().spawnFleet(getAnchor(), 0, 0, fleet);

      fleet.setPreferredResupplyLocation(getAnchor());
      
      if (type.equals("scout") || type.equals("raiders")) {
         fleet.addAssignment(FleetAssignment.RAID_SYSTEM, null, 30);
         fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
      } else {
         if ((float) Math.random() > 0.3f) {
            //fleet.addAssignment(FleetAssignment.RAID_SYSTEM, null, 30);
            fleet.addAssignment(FleetAssignment.ATTACK_LOCATION, station, 50);
            fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
         } else {
            fleet.addAssignment(FleetAssignment.DEFEND_LOCATION, getAnchor(), 20);
            fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, getAnchor(), 1000);
         }
      }
      return fleet;
   }

}


[close]

Thanks in advance! :D
Logged

PCCL

  • Admiral
  • *****
  • Posts: 2016
  • still gunnyfreak
    • View Profile
Re: Faction Spawn Points
« Reply #1 on: June 12, 2012, 07:43:54 PM »

Quote
SectorEntityToken token = system.createToken(15000, 0);   
    system.addSpawnPoint(new UnknownSpawnPoint(CorvusIV, 45, 30, 1, token));

You didn't define "CorvusIV" as far as I can tell

do you know how to use getentitybyname?
Logged
mmm.... tartiflette

MiniFishy

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Faction Spawn Points
« Reply #2 on: June 12, 2012, 11:36:55 PM »

do you know how to use getentitybyname?

I do not  :D
Logged

PCCL

  • Admiral
  • *****
  • Posts: 2016
  • still gunnyfreak
    • View Profile
Re: Faction Spawn Points
« Reply #3 on: June 13, 2012, 12:59:04 AM »

quoted from paul's tutorial:
Quote
If you want to set your spawn points to be tied to particular planets or stations, you can do that too – you just have to get the planet or station and use it in place of a token. Here is an example:

SectorEntityToken CorvusIIIA = system.getEntityByName("Corvus IIIA");
system.addSpawnPoint(new GRPirateSpawnPoint(sector, system, 5, 5, CorvusIIIA));

so if you want your spawn point to be on corvus IV your code would look something like this:

instead of:
Quote
SectorEntityToken token = system.createToken(15000, 0);   
    system.addSpawnPoint(new UnknownSpawnPoint(CorvusIV, 45, 30, 1, token));

you would have:
Quote
SectorEntityToken CorvusIV = system.getEntityByName("Corvus IV");
system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV));

judging by your code, it's a bit hard to tell what you trying to do... I assumed you're trying to make it spawn on the planet, are you trying to make the spawn point in orbit of the planet? Like, so it spawns out of thin air around the planet? Or is it supposed to spawn from a station or something?

As a side note, what is "station2"?
Here :
Quote
      system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 14, 1, token, station2));
Logged
mmm.... tartiflette

MiniFishy

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Faction Spawn Points
« Reply #4 on: June 13, 2012, 02:41:53 AM »

To be honest, I don't even know.
I was literally copying and pasting from tutorials I could find to try and fix multiple problems, it's all new to me >.<
All I'm trying to do is get the fleet to spawn somewhere :P

Now I'm getting this error, having pasted your code into where it should be
Spoiler
Caused by: org.codehaus.commons.compiler.CompileException: File data/scripts/world/FishyGen.java, Line 25, Column 22: No applicable constructor/method found for actual parameters "com.fs.starfarer.api.campaign.SectorAPI, com.fs.starfarer.api.campaign.StarSystemAPI, int, int, com.fs.starfarer.api.campaign.SectorEntityToken"; candidates are: "data.scripts.world.UnknownSpawnPoint(com.fs.starfarer.api.campaign.SectorAPI, com.fs.starfarer.api.campaign.LocationAPI, float, int, com.fs.starfarer.api.campaign.SectorEntityToken, com.fs.starfarer.api.campaign.SectorEntityToken)"
[close]

I also removed the:

token = system.createToken(15000, -15000);
      system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 14, 1, token, station2));

from the code if that makes any difference.

Thanks for your help!
Logged

Tezarius

  • Lieutenant
  • **
  • Posts: 66
    • View Profile
Re: Faction Spawn Points
« Reply #5 on: June 13, 2012, 03:23:04 AM »

Problem is here:
Code
system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV));

There are 2 ways:
1. In the UnknownSpawnPoint.java
Replace this
Code
public UnknownSpawnPoint(SectorAPI sector, LocationAPI location,
                     float daysInterval, int maxFleets, SectorEntityToken anchor,
                     SectorEntityToken station) {
      super(sector, location, daysInterval, maxFleets, anchor);
      this.station = station;}
by this
Code
public UnknownSpawnPoint(SectorAPI sector, LocationAPI location,
                     float daysInterval, int maxFleets, SectorEntityToken anchor) {
      super(sector, location, daysInterval, maxFleets, anchor);}

2. Or you should just add station entity like this:
Code
SectorEntityToken HegemonyStation = system.getEntityByName("Orbital Station");
system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV, HegemonyStation));
« Last Edit: June 13, 2012, 03:27:04 AM by Tezarius »
Logged

MiniFishy

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Faction Spawn Points
« Reply #6 on: June 13, 2012, 03:40:59 AM »

2. Or you should just add station entity like this:
Code
SectorEntityToken HegemonyStation = system.getEntityByName("Orbital Station");
system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV, HegemonyStation));
Having done that takes me back to this error in the log:
Code
Caused by: org.codehaus.commons.compiler.CompileException: File data/scripts/world/FishyGen.java, Line 25, Column 74: Unknown variable or type "CorvusIV"
Logged

Tezarius

  • Lieutenant
  • **
  • Posts: 66
    • View Profile
Re: Faction Spawn Points
« Reply #7 on: June 13, 2012, 03:49:55 AM »

Omg, you should not remove this line:
Code
SectorEntityToken CorvusIV = system.getEntityByName("Corvus IV"); 

So, to create spawn point you must have all this lines:
Code
StarSystemAPI system = sector.getStarSystem("Corvus");
SectorEntityToken CorvusIV = system.getEntityByName("Corvus IV");
SectorEntityToken HegemonyStation = system.getEntityByName("Orbital Station");
system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV, HegemonyStation));

MiniFishy

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Faction Spawn Points
« Reply #8 on: June 13, 2012, 04:03:21 AM »

I see, oh lord I'm silly :P
It loads up perfectly now, thanks!

As a side note, that means they should spawn at the Hegemony station, correct?
If so, I've been through a few months on my test campaign and I'm yet to see them spawn.
Logged

Tezarius

  • Lieutenant
  • **
  • Posts: 66
    • View Profile
Re: Faction Spawn Points
« Reply #9 on: June 13, 2012, 04:39:23 AM »

No, according to the UnknownSpawnPoint.java, new TriTachion fleets will spawn at the planet Corvus IV and with some chance lay on the attack course to the Hegemony station

Btw, for testing reasons you can replace this
Code
system.addSpawnPoint(new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV, HegemonyStation));
by this
Code
UnknownSpawnPoint UnknownOne = new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV, HegemonyStation);
system.addSpawnPoint(UnknownOne)
for (int i = 0; i < 10; i++)              
UnknownOne.spawnFleet();
So, in the start point of the new game you will see 10 fleets around Corvus IV

MiniFishy

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Faction Spawn Points
« Reply #10 on: June 13, 2012, 05:12:20 AM »

I feel like such a noob asking so many questions  ::)

After replacing that line of code still nothing appears around Corvus IV.

Coding obviously doesn't like me :P
Logged

Tezarius

  • Lieutenant
  • **
  • Posts: 66
    • View Profile
Re: Faction Spawn Points
« Reply #11 on: June 13, 2012, 05:49:01 AM »

Sorry, there was a small error (but game would not even start with it...)
Here correct one
Code
UnknownSpawnPoint UnknownOne = new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV, HegemonyStation);
system.addSpawnPoint(UnknownOne);
for (int i = 0; i < 10; i++)               
UnknownOne.spawnFleet();

I think you need to check
1. The mod is activated in the games "Mods" menu
2. The  data\world\generators.csv file has a row "data.scripts.world.FishyGen"

MiniFishy

  • Ensign
  • *
  • Posts: 32
    • View Profile
Re: Faction Spawn Points
« Reply #12 on: June 13, 2012, 05:55:53 AM »

Sorry, there was a small error (but game would not even start with it...)
Here correct one
Code
UnknownSpawnPoint UnknownOne = new UnknownSpawnPoint(sector, system, 5, 5, CorvusIV, HegemonyStation);
system.addSpawnPoint(UnknownOne);
for (int i = 0; i < 10; i++)               
UnknownOne.spawnFleet();

I figured that one out myself! :D I'm slowly learning!

2. The  data\world\generators.csv file has a row "data.scripts.world.FishyGen"

I mis-read Paul's tutorial, I had the generator file in data/scripts/world. Silly me!

Thanks so much man! It works :D
Logged

Tezarius

  • Lieutenant
  • **
  • Posts: 66
    • View Profile
Re: Faction Spawn Points
« Reply #13 on: June 13, 2012, 06:06:24 AM »

You are welcome.  ;)