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)

Pages: 1 ... 248 249 [250] 251 252 ... 706

Author Topic: Misc modding questions that are too minor to warrant their own thread  (Read 1699971 times)

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3735 on: January 08, 2018, 08:40:23 AM »


I did paste this into Hybrasil.java:

PlanetAPI penumbros = system.addPlanet("penumbros_archeus", hybrasil_star, "Penumbros", "jungle", 45f, 180f, 15000f, 600f);
penumbros.setCustomDescriptionId("planet_culann");

And it seemed to work fine - planet shows up, can click show planet info fine.

Wow yup, copy-pasted my code into that file, removed the other one, and it solves the issue. Hm. So I guess I have to copy/replace each system file that I want to add things to.

You really shouldn't need to, that code doesn't care where it runs. Well, I mean, if you want autogenerated jump-points related to what you're adding, that could be a problem since that's called from Hybrasil.java etc. But that aside, I don't see why you couldn't do what you're doing - I suspect the issue was how you got the star, and it wasn't the right entity. For example, maybe you got hold of the star's gravity well in hyperspace instead?
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3736 on: January 08, 2018, 12:00:05 PM »

You really shouldn't need to, that code doesn't care where it runs. Well, I mean, if you want autogenerated jump-points related to what you're adding, that could be a problem since that's called from Hybrasil.java etc. But that aside, I don't see why you couldn't do what you're doing - I suspect the issue was how you got the star, and it wasn't the right entity. For example, maybe you got hold of the star's gravity well in hyperspace instead?

Yeah I don't really understand it myself.  :) The ambiguity of the error makes it quite difficult to place.

The only other thing I could come up with, after pondering it quite a bit, was the use of the "new" operator somehow causing weirdness. At first I thought it was that the star had to just be initialized for some reason, but that doesn't make sense.


My thought process
: When I generated a custom planet and market - literally using the exact same method - in Galatia for use with the tutorial, it seemed to work just fine. The market showed up and you could click "Show Info" on any relevant entity. The market conditions appeared, etc. That's why I blindly re-used that method in 3 new systems, because it seemed "tried and tested." Not so.

Now, the only difference between anything implemented between those two planets is that one has a custom implemented market script, like Derinkuyu, and one does not. So, also like Derinkuyu, the market is added to the global economy during: ArcheusTutorialMissionEvent.endGalatiaPortionofMission() using:

        Global.getSector().getEconomy().addMarket(eldrus.getMarket());

where:

"eldrus" is returned by:

       SectorEntityToken eldrus = system.getEntityById("eldrus");


That being said, I had originally populated two additional planets in Isirah, again same method, and added markets to them using a .JSON file in the data/campaign/econ directory - and that also causes the error.  ::)
The market works fine, you can go there, see fleets spawn, even dock and buy things but the second you try and view the planet info, or any other planet that would pull its info within its range, you get the error.


Edit** Ok... you know what, looking at it again, I wonder if the key here is:

system.getEntityById("eldrus")

being used to put the market into the economy.


So,
Here is the script generating eldrus in galatia:
Spoiler
        StarSystemAPI system = sector.getStarSystem("galatia");

        // create the star and generate the hyperspace anchor for this system
        PlanetAPI star = system.getStar();

        // SectorEntityToken creation goes from star -> fringe
        PlanetAPI eldrus = system.addPlanet("eldrus", star, "Eldrus", "barren", 130f, 120f, 12000f, 600f);
        eldrus.setCustomDescriptionId("planet_eldrus");
        eldrus.setFaction(ArcheusFactions.ARCHEUS);
        eldrus.setInteractionImage("illustrations", "vacuum_colony");


        // create a market for eldrus - not connected to the rest of the economy to start with
        MarketAPI market = Global.getFactory().createMarket("eldrus_market", eldrus.getName(), 0);
        market.setSize(1);

        market.setSurveyLevel(MarketAPI.SurveyLevel.FULL);
        market.setPrimaryEntity(eldrus);

        market.setFactionId(eldrus.getFaction().getId());
        market.addCondition(Conditions.POPULATION_2);
        market.addCondition(Conditions.OUTPOST);

        market.addSubmarket(Submarkets.SUBMARKET_OPEN);
        market.addSubmarket(Submarkets.SUBMARKET_BLACK);
        market.addSubmarket(Submarkets.SUBMARKET_STORAGE);

        eldrus.setMarket(market);
        market.getCommDirectory().addMissionBoard();
        eldrus.addScript(new GalatiaMarketScript(market));


[close]

And one making a station in corvus:
Spoiler
        StarSystemAPI system = sector.getStarSystem("corvus");
        PlanetAPI star = system.getStar();

        //add station
        SectorEntityToken tg_station = system.addCustomEntity("jangalas_rest_station", "Jangala's Rest", "station_side02", ArcheusFactions.TRADERGUILDS);
        tg_station.setCircularOrbitPointingDown(star, 315f, 7000f, 360f);
        tg_station.setCustomDescriptionId("traderguilds_station_corvus");

[close]

The station has a market added through the .JSON file. -No error.

The planet has a market added to the global economy as displayed above. -No error.

Now if I put this:
Spoiler
        PlanetAPI penumbros = system.addPlanet("penumbros_archeus", star, "Penumbros", "jungle", 145, 180, 7000, 600);
        penumbros.setCustomDescriptionId("planet_penumbros");

        SectorEntityToken fortress = system.addCustomEntity("eldritch_fortress", "Eldritch Fortress", "station_side03", ArcheusFactions.ARCHEUS);
        fortress.setCircularOrbitPointingDown(system.getEntityById("penumbros_archeus"), 140f, 250f, 600f);
        fortress.setCustomDescriptionId("eldritch_fortress");
        fortress.setInteractionImage("illustrations", "eldritch_fortress");

[close]

 in either file at all, whether I add a market through the JSON file, or not, but I don't do what I did with Eldrus and add a market to the global economy in ArcheusTutorialMissionEvent.endGalatiaPortionofMission() like above. -Error.

That's the extent to which I understand what's going on. So, if anyone sees something I don't here please let me know! I would really like to not run into this error again in the future.  :P
« Last Edit: January 08, 2018, 12:20:57 PM by Morrokain »
Logged

King Alfonzo

  • Admiral
  • *****
  • Posts: 679
  • -- D O C T O R --
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3737 on: January 08, 2018, 02:56:18 PM »

Make sure to change your spawner code so that it doesn't try to spawn fleets at the market's location, since the fake market doesn't have one.

Um, forgive me Hist, but, how? I could set up the weighted picker to pick the fake market, but then how do you tell the game to spawn from an object and not the market? I think this is the fundamental things I couldn't, and still can't, wrap my head around. I mean, I think I can see bits and pieces in the IBB script about picking the nearest market, and a separate picker that picks a hideout location, with the idea that the IBB fleet picks the market then spawns at the hideout location, but what I don't understand is how this is done.

Regardless, you and Alex have been a tremendous help thus far, and I thank you profusely for helping me out thus far.

NightKev

  • Commander
  • ***
  • Posts: 104
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3738 on: January 09, 2018, 04:51:13 AM »

I've been trying to change the personality of a ship based on which hullmod it has (no effect if the ship has an officer) and so far I think I've been successful, but there doesn't seem to be a way to detect when hullmods are removed and thus restore the ship to the default "Steady" personality, since it seems changing the ship's personality is permanent (unless I've missed a non-permanent method of doing it?). Is there any way to work around this?

For reference, the code for my hullmod is here:
Code
package org.tc.autonomous;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.combat.BaseHullMod;
import com.fs.starfarer.api.combat.ShipAPI;
import org.apache.log4j.Logger;

public abstract class AbstractPersonalityHullMod extends BaseHullMod {
    private static Logger LOG = Global.getLogger(AutonomousCommandsPlugin.class);
    private static final String PREFIX = "autonomous_personality_";

    private String personality;

    AbstractPersonalityHullMod(String personality) {
        this.personality = personality;
    }

    @Override
    public boolean isApplicableToShip(ShipAPI ship) {
        for (String hullMod : ship.getVariant().getHullMods()) {
            if (hullMod.startsWith(PREFIX) && !hullMod.equals(PREFIX + personality)) {
                return false;
            }
        }
        return true;
    }

    @Override
    public String getUnapplicableReason(ShipAPI ship) {
        return "Personality hullmods are mutually exclusive";
    }

    @Override
    public void advanceInCombat(ShipAPI ship, float amount) {
        if (ship.getCaptain() != null && ship.getCaptain().isDefault()) {
            ship.getCaptain().setPersonality(personality);
            LOG.info("Personality [" + personality + "] applied to ship [" + ship.getName() + "]");
        }
    }
}
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3739 on: January 09, 2018, 06:17:13 AM »

Make sure to change your spawner code so that it doesn't try to spawn fleets at the market's location, since the fake market doesn't have one.

Um, forgive me Hist, but, how? I could set up the weighted picker to pick the fake market, but then how do you tell the game to spawn from an object and not the market? I think this is the fundamental things I couldn't, and still can't, wrap my head around. I mean, I think I can see bits and pieces in the IBB script about picking the nearest market, and a separate picker that picks a hideout location, with the idea that the IBB fleet picks the market then spawns at the hideout location, but what I don't understand is how this is done.
Code: java
CampaignFleetAPI fleet = FleetFactoryV2.createFleet(params);

SectorEntityToken spawnEntity = methodToGetASpawnPoint();  // like a planet or such
LocationAPI location = spawnEntity.getContainingLocation();  // a star system, or hyperspace
// adds our new fleet into the containing location
location.addEntity(fleet);
// positions fleet on top of the spawn entity
fleet.setLocation(spawnEntity.getLocation().x, spawnEntity.getLocation().y);

Or to spawn in hyperspace near the player, LuddicPathFleetManager does this:
Code: java
Vector2f loc = Misc.pickHyperLocationNotNearPlayer(target.getLocation(), Global.getSettings().getMaxSensorRange() + 500f);
Global.getSector().getHyperspace().addEntity(fleet);
fleet.setLocation(loc.x, loc.y);
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3740 on: January 09, 2018, 10:42:01 AM »

I've been trying to change the personality of a ship based on which hullmod it has (no effect if the ship has an officer) and so far I think I've been successful, but there doesn't seem to be a way to detect when hullmods are removed and thus restore the ship to the default "Steady" personality, since it seems changing the ship's personality is permanent (unless I've missed a non-permanent method of doing it?). Is there any way to work around this?

Hmm - one thing that comes to mind is creating a ship AI in your mod's ModPlugin.pickShipAI() and using the ShipAIConfig.personalityOverride to set the personality, which will only last for the duration of the battle.

See: CoreLifecyclePluginImpl.pickShipAI() for an example of how that might work. That one sets a specific AI config for automated ships; in your case you'd test for the presence of your relevant hullmods and set the personality override based on that.

This will not be compatible with mods that modify ship AI, though - i.e. if another mod wants to modify the ship AI config based on some parameters, only one will take effect - but I'm not sure how much of a practical issue that is.

Edit: added ShipAIPlugin.getConfig() method to make this sort of stuff easier and doable on the fly.
Logged

King Alfonzo

  • Admiral
  • *****
  • Posts: 679
  • -- D O C T O R --
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3741 on: January 11, 2018, 01:36:10 AM »

Code: java
CampaignFleetAPI fleet = FleetFactoryV2.createFleet(params);

SectorEntityToken spawnEntity = methodToGetASpawnPoint();  // like a planet or such
LocationAPI location = spawnEntity.getContainingLocation();  // a star system, or hyperspace
// adds our new fleet into the containing location
location.addEntity(fleet);
// positions fleet on top of the spawn entity
fleet.setLocation(spawnEntity.getLocation().x, spawnEntity.getLocation().y);

Or to spawn in hyperspace near the player, LuddicPathFleetManager does this:
Code: java
Vector2f loc = Misc.pickHyperLocationNotNearPlayer(target.getLocation(), Global.getSettings().getMaxSensorRange() + 500f);
Global.getSector().getHyperspace().addEntity(fleet);
fleet.setLocation(loc.x, loc.y);


Hot Damn Histidine thank you! I finally have a working script that spawns things from entities! Many thanks for the help, Hist!

EDIT: ...aaaand now something has gone horribly wrong.

I've been using GetMaxFleets to try and keep the amount of spawned fleets low. For the following example, I have set the number of fleets for the red and orange faction (and probably every single other unidentified contact in the following image) to 1:

Spoiler
[close]

Yeah, that hasn't happened.

Now, I currently have three different fleetmanagers within this mod, and one of them has a maxfleets of 10, and the other two has their MaxFleets set to 1. So, within the context of a single mod, if you set different maxfleets, does it just pick the largest and use it for all of them? Or am I doing something horrifically wrong?

Code
public class DracoFleetManager extends BaseLimitedFleetManager {
public static int DRACO_MAX_FLEETS = 1;

@Override
protected int getMaxFleets() {
return DRACO_MAX_FLEETS;
}
...

Code
public class MessFleetManager extends BaseLimitedFleetManager {
public static int MESS_MAX_FLEETS = 10;

@Override
protected int getMaxFleets() {
return MESS_MAX_FLEETS;
}
...

Code
public class FangFleetManager extends BaseLimitedFleetManager {
public static int FANG_MAX_FLEETS = 1;

@Override
protected int getMaxFleets() { return FANG_MAX_FLEETS; }
...

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3742 on: January 13, 2018, 07:20:35 AM »

How easy would it be to remove the flux generation of the "Engage Fighters" command?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3743 on: January 13, 2018, 10:04:24 AM »

How easy would it be to remove the flux generation of the "Engage Fighters" command?

Basically impossible, it's hardcoded.
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3744 on: January 13, 2018, 10:26:36 AM »

How easy would it be to remove the flux generation of the "Engage Fighters" command?

Basically impossible, it's hardcoded.

Ah ok that's what I suspected. Thanks!  :)
Logged

King Alfonzo

  • Admiral
  • *****
  • Posts: 679
  • -- D O C T O R --
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3745 on: January 13, 2018, 08:21:31 PM »

Update on my rampant spawning bug, check the log. I am bamboozled.

The message is consistent when looking for the fleet manager:

Code
508730 [Thread-4] INFO  com.fs.starfarer.api.impl.campaign.fleets.BaseLimitedFleetManager  - 0 out of a maximum 1 fleets in play for [data.campaign.fleets.DracoFleetManager]
508735 [Thread-4] INFO  com.fs.starfarer.api.impl.campaign.fleets.BaseLimitedFleetManager  - Could not spawn fleet - returned null
508735 [Thread-4] INFO  com.fs.starfarer.api.impl.campaign.fleets.BaseLimitedFleetManager  - 0 out of a maximum 1 fleets in play for [data.campaign.fleets.FangFleetManager]
508741 [Thread-4] INFO  com.fs.starfarer.api.impl.campaign.fleets.BaseLimitedFleetManager  - Could not spawn fleet - returned null

This is clearly wrong, as the game is spawning the fleets at the right place, but doesn't seem to be aware that it is spawning the fleet. Or it's spawning the fleet on a null response? But then, why is it working for the Mess faction file, but not these two, considering the coding language is almost identical? I am really confused by this - would anyone have an inkling of what I've done wrong?

EDIT: There was some remaining code from the LuddicPathFleetManager that looked for a source market. Without this section of code, the fleetmanager worked perfectly. I still don't get why the fleetmanager worked the way it did though.

Many thanks for everyone for the help!

EDIT2: So, so very sorry guys. The absolutely final question I'll ask for the forseeable future: How does one effect the post-battle loot drops? I've taken a gander through the core game and the Templar mod, as well as the forum and it's not really clear to me. Aim is to add a commodity to drop post-battle for a specific faction - not from an event, but in general. Now I've seen something in the SeededRemnantFleetManager about this, but it refers to tags which as far as I can tell, don't actually match with the commodity information. If anyone could put me to rights, I'd appreciate it.

Harmful Mechanic

  • Admiral
  • *****
  • Posts: 1340
  • On break.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3746 on: January 14, 2018, 08:14:18 PM »

Quick question, is it possible to reduce the range of weapons only for a single mount type? I'm looking to reduce the range of only ballistic weapons with a hullmod.

Specifically, I'm looking to reduce ballistic weapon range by 100 for smalls, 200 for mediums, and 300 for larges. Might add a PD exception.
« Last Edit: January 14, 2018, 08:38:12 PM by Soren »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3747 on: January 14, 2018, 08:50:11 PM »

There's MutableShipStatsAPI.getBallisticWeaponRangeBonus() (which I guess you're aware of), but that's not going to let you differentiate by mount size, and there's nothing that I'm aware of that would.
Logged

Harmful Mechanic

  • Admiral
  • *****
  • Posts: 1340
  • On break.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3748 on: January 14, 2018, 08:54:05 PM »

Yeah, I found that just as I hit send; I'm kind of an idiot.

I'll go with a flat percentage, then.
Logged

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3749 on: January 14, 2018, 11:13:12 PM »

Quick question, is it possible to reduce the range of weapons only for a single mount type? I'm looking to reduce the range of only ballistic weapons with a hullmod.

Specifically, I'm looking to reduce ballistic weapon range by 100 for smalls, 200 for mediums, and 300 for larges. Might add a PD exception.

This code should filter by what you are looking for- Only ballistic, different values for small, medium, large- and a PD exception. But, I haven't found a method to modify the range of those weapons. Not sure you can.

Spoiler
   public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
      List weapons = ship.getAllWeapons();
      Iterator iter = weapons.iterator();
      while (iter.hasNext()) {
         WeaponAPI weapon = (WeaponAPI)iter.next();
         if (weapon.getType() == WeaponType.BALLISTIC && !weapon.hasAIHint(WeaponAPI.AIHints.PD)) {
             if (weapon.getSize() == WeaponSize.LARGE) {
                    weapon.getRange();
                }
                if (weapon.getSize() == WeaponSize.MEDIUM) {
                    weapon.getRange();
                }
                if (weapon.getSize() == WeaponSize.SMALL) {
                    weapon.getRange();
                }
            }
        }
    }
[close]

                   " weapon.getRange();" Is the placeholder for the actual code to modify the weapon's range. It wouldn't do that, itself.

I've only modified range across all weapons of a type using MutableShipStatsAPI and I don't think that would work here.

This will get you started though, in case someone knows something I don't.  ;)

**Edit** Submitted this late it seems. It was already pretty much answered. Still, something useful I guess.
« Last Edit: January 14, 2018, 11:19:38 PM by Morrokain »
Logged
Pages: 1 ... 248 249 [250] 251 252 ... 706