Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 375 376 [377] 378 379 ... 710

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

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24127
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5640 on: November 10, 2019, 12:07:10 PM »

Return false, yeah. That method is part of the EveryFrameScript interface so you have to implement it.
Logged

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5641 on: November 10, 2019, 01:49:12 PM »

There sure is:
Code: java
            boolean retreatDirectly = true;
            ship.setRetreating(true, retreatDirectly);
I tried this code, but it doesn't seem to work, either in simulation or a real battle... I posted a new thread for this problem here with a bit more detail on what's going on:

https://fractalsoftworks.com/forum/index.php?topic=17206.0
Logged

Kaykat

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5642 on: November 11, 2019, 01:35:59 PM »

How do I change the description of some ships/weapons in a mod? I know I gotta change the descriptions.csv and when I copied my changes into the folder it worked fine but then it reverted itself the next time I played .-. is there something else I gotta mess with to make it permanent?

Edit: Oh, it's not mine btw, I just wanna make a few corrections to some spelling in another
Logged
If all the mod authors weren't so entitled and rude all the time maybe I would've stayed and contributed, au revoir >_>

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24127
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5643 on: November 11, 2019, 01:43:27 PM »

It shouldn't revert itself if it's just csv changes, that's strange. Unless, say, you update the mod, or you had the file open in multiple places and somehow ended up saving an unmodified version later, or something like that.

What you're doing sounds like it should work, so I'd give it another shot.
Logged

Kaykat

  • Ensign
  • *
  • Posts: 8
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5644 on: November 12, 2019, 12:53:06 AM »

...somehow ended up saving an unmodified version later, or something like that.

omg of course that is exactly what i freaking did too >_<

lol thanks for the answer anyway!
Logged
If all the mod authors weren't so entitled and rude all the time maybe I would've stayed and contributed, au revoir >_>

Sinosauropteryx

  • Captain
  • ****
  • Posts: 262
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5645 on: November 12, 2019, 06:29:39 AM »

Is it possible to write custom values for damage, DPS, etc in a weapon's codex? For example, if a gun added a bunch of projectiles through a script, can I get the stat block to represent that?

Also, is there a way to find out how close a weapon is to finishing its next reload? For example, if I wanted to trigger something when a weapon is 50% finished reloading the shot it's reloading.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24127
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5646 on: November 12, 2019, 07:59:20 AM »

omg of course that is exactly what i freaking did too >_<

Happens to the best of us :)

Is it possible to write custom values for damage, DPS, etc in a weapon's codex? For example, if a gun added a bunch of projectiles through a script, can I get the stat block to represent that?

Not stat blocks, specifically, but you can add custom text with highlights, like vanilla does for some weapons (Devastator, Sabot, Ion Cannon, etc). See

customPrimary   customPrimaryHL   customAncillary   customAncillaryHL

In weapon_data.csv. The *ancillary ones are for text after the second block of data.

Also, is there a way to find out how close a weapon is to finishing its next reload? For example, if I wanted to trigger something when a weapon is 50% finished reloading the shot it's reloading.

Hmm - WeaponAPI.getCooldown()/getCooldownRemaining()? Or are those insufficient?
Logged

prav

  • Captain
  • ****
  • Posts: 395
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5647 on: November 12, 2019, 08:38:20 AM »

I've got a custom submarket, extending MilitarySubmarketPlugin, that's mostly working, but it seems to update its ships and weapons stock every time I reopen the market, instead of the default once a month. I think the problem is that okToUpdateShipsAndWeapons() from BaseSubmarketPlugin is always returning true, but I don't know why. What kind of snag am I running into here?

Abbreviated:
Spoiler
Code
[... omitted ...]

public class prv_labmarket extends MilitarySubmarketPlugin {

[... omitted ...]

@Override
public void updateCargoPrePlayerInteraction() {
float seconds = Global.getSector().getClock().convertToSeconds(sinceLastCargoUpdate);
addAndRemoveStockpiledResources(seconds, false, true, true);
sinceLastCargoUpdate = 0f;

if (okToUpdateShipsAndWeapons()) {
sinceSWUpdate = 0f;

WeightedRandomPicker<String> factionPicker = new WeightedRandomPicker<String>();

String owner = market.getFactionId();
List<FactionAPI> factions = Global.getSector().getAllFactions();
for(FactionAPI faction : factions){
if(faction.getRelationshipLevel(owner).isAtWorst(ALLY_THRESHOLD)){
factionPicker.add(faction.getId(),10f);
}
}
if (factionPicker.isEmpty()) {
factionPicker.add(owner);
}

pruneWeapons(0f);
addWeaponsMintier(WEAPON_COUNT_NATIVE, Math.round(WEAPON_COUNT_NATIVE * 1.5f) , 3,2, submarket.getFaction().getId());
addWeaponsMintier(WEAPON_COUNT_ALLY, Math.round(WEAPON_COUNT_ALLY * 1.5f) , 3,2, factionPicker);
addFightersMintier(WING_COUNT, Math.round(WING_COUNT * 1.5f), 3,2, market.getFactionId());
addHullModsMintier(4, 2,itemGenRandom.nextInt(HULLMOD_COUNT));

if(Math.random() < GOODYCHANCE){
addGoodies(0,3);
}

float stability = market.getStabilityValue();
float sMult = Math.max(0.1f, stability / 10f);
getCargo().getMothballedShips().clear();
addShips(submarket.getFaction().getId(),
  50f * sMult, // combat
  15f * sMult, // freighter
  10f * sMult, // tanker
  20f * sMult, // transport
  10f * sMult, // liner
  10f * sMult, // utilityPts
  null, // qualityOverride
  sMult, // qualityMod
  null,
  null);
}

getCargo().sort();
}

[... omitted ...]

}
[close]

Full class:
Spoiler
Code
package campaign.submarkets;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.*;
import com.fs.starfarer.api.impl.campaign.fleets.DefaultFleetInflater;
import com.fs.starfarer.api.impl.campaign.ids.Items;
import com.fs.starfarer.api.impl.campaign.submarkets.MilitarySubmarketPlugin;
import com.fs.starfarer.api.loading.FighterWingSpecAPI;
import com.fs.starfarer.api.loading.HullModSpecAPI;
import com.fs.starfarer.api.loading.WeaponSpecAPI;
import com.fs.starfarer.api.util.Misc;
import com.fs.starfarer.api.util.WeightedRandomPicker;

import java.util.List;

public class prv_labmarket extends MilitarySubmarketPlugin {

private static final int WEAPON_COUNT_NATIVE = 3; // n to 1.5 n
private static final int WEAPON_COUNT_ALLY = 3; // n to 1.5 n
private static final int WING_COUNT = 3; // n to 1.5 n
private static final int HULLMOD_COUNT = 3; // 0 to n-1
private static final float GOODYCHANCE = 0.33f;
private static final RepLevel ALLY_THRESHOLD = RepLevel.WELCOMING; // +25

@Override
public String getName() {
return Misc.ucFirst(submarket.getFaction().getPersonNamePrefix()) + "\n" + "R&D";
}

@Override
protected boolean requiresCommission(RepLevel req) {
return false;
}

@Override
public void updateCargoPrePlayerInteraction() {
float seconds = Global.getSector().getClock().convertToSeconds(sinceLastCargoUpdate);
addAndRemoveStockpiledResources(seconds, false, true, true);
sinceLastCargoUpdate = 0f;

if (okToUpdateShipsAndWeapons()) {
sinceSWUpdate = 0f;

WeightedRandomPicker<String> factionPicker = new WeightedRandomPicker<String>();

String owner = market.getFactionId();
List<FactionAPI> factions = Global.getSector().getAllFactions();
for(FactionAPI faction : factions){
if(faction.getRelationshipLevel(owner).isAtWorst(ALLY_THRESHOLD)){
factionPicker.add(faction.getId(),10f);
}
}
if (factionPicker.isEmpty()) {
factionPicker.add(owner);
}

pruneWeapons(0f);
addWeaponsMintier(WEAPON_COUNT_NATIVE, Math.round(WEAPON_COUNT_NATIVE * 1.5f) , 3,2, submarket.getFaction().getId());
addWeaponsMintier(WEAPON_COUNT_ALLY, Math.round(WEAPON_COUNT_ALLY * 1.5f) , 3,2, factionPicker);
addFightersMintier(WING_COUNT, Math.round(WING_COUNT * 1.5f), 3,2, market.getFactionId());
addHullModsMintier(4, 2,itemGenRandom.nextInt(HULLMOD_COUNT));

if(Math.random() < GOODYCHANCE){
addGoodies(0,3);
}

float stability = market.getStabilityValue();
float sMult = Math.max(0.1f, stability / 10f);
getCargo().getMothballedShips().clear();
addShips(submarket.getFaction().getId(),
  50f * sMult, // combat
  15f * sMult, // freighter
  10f * sMult, // tanker
  20f * sMult, // transport
  10f * sMult, // liner
  10f * sMult, // utilityPts
  null, // qualityOverride
  sMult, // qualityMod
  null,
  null);
}

getCargo().sort();
}

protected void addGoodies(int min, int max){
int num = min + itemGenRandom.nextInt(max - min + 1);
WeightedRandomPicker<WeaponSpecAPI> picker = new WeightedRandomPicker<WeaponSpecAPI>(itemGenRandom);
for (String id : Global.getSector().getAllWeaponIds()) {
WeaponSpecAPI spec = Global.getSettings().getWeaponSpec(id);
float p = 1f;
if (spec.getTags().contains("prv_lab_bp")) {
picker.add(spec, p);
}
}

for (int i = 0; i < num && !picker.isEmpty(); i++) {
WeaponSpecAPI spec = picker.pick();

int count = 1;

CargoAPI cargo = submarket.getCargo();
cargo.addWeapons(spec.getWeaponId(), count);
}
}

protected void addWeaponsMintier(int min, int max, int maxTier, int minTier, WeightedRandomPicker<String> factionPicker) {
int num = min + itemGenRandom.nextInt(max - min + 1);
for (int i = 0; i < num; i++) {
String factionId = factionPicker.pick();
addWeaponsMintier(1, 1, maxTier, minTier, factionId);
}

}

protected void addWeaponsMintier(int min, int max, int maxTier, int minTier, String factionId) {
if (factionId == null) factionId = market.getFactionId();

int num = min + itemGenRandom.nextInt(max - min + 1);
float quality = Misc.getShipQuality(market, factionId);

FactionAPI faction = Global.getSector().getFaction(factionId);

WeightedRandomPicker<WeaponSpecAPI> picker = new WeightedRandomPicker<WeaponSpecAPI>(itemGenRandom);
for (String id : faction.getKnownWeapons()) {
WeaponSpecAPI spec = Global.getSettings().getWeaponSpec(id);
if (spec.getTier() > maxTier) continue;
if (spec.getTier() < minTier) continue;

float p = DefaultFleetInflater.getTierProbability(spec.getTier(), quality);
p = 1f;
picker.add(spec, p);
}

for (int i = 0; i < num && !picker.isEmpty(); i++) {
WeaponSpecAPI spec = picker.pick();

int count = 2;
switch (spec.getSize()) {
case LARGE: count = 2; break;
case MEDIUM: count = 4; break;
case SMALL: count = 8; break;
}

count = count + itemGenRandom.nextInt(count + 1) - count/2;

CargoAPI cargo = submarket.getCargo();
cargo.addWeapons(spec.getWeaponId(), count);
}
}

protected void addFightersMintier(int min, int max, int maxTier, int minTier, String factionId) {
if (factionId == null) factionId = market.getFactionId();

int num = min + itemGenRandom.nextInt(max - min + 1);
float quality = Misc.getShipQuality(market, factionId);

FactionAPI faction = Global.getSector().getFaction(factionId);

WeightedRandomPicker<FighterWingSpecAPI> picker = new WeightedRandomPicker<FighterWingSpecAPI>(itemGenRandom);
for (String id : faction.getKnownFighters()) {
FighterWingSpecAPI spec = Global.getSettings().getFighterWingSpec(id);
if (spec.getTier() > maxTier) continue;
if (spec.getTier() < minTier) continue;

float p = DefaultFleetInflater.getTierProbability(spec.getTier(), quality);
picker.add(spec, p);
}

for (int i = 0; i < num && !picker.isEmpty(); i++) {
FighterWingSpecAPI spec = picker.pick();

int count = 2;
switch (spec.getRole()) {
case ASSAULT: count = 2; break;
case BOMBER: count = 2; break;
case INTERCEPTOR: count = 4; break;
case FIGHTER: count = 3; break;
case SUPPORT: count = 2; break;
}

count = count + itemGenRandom.nextInt(count + 1) - count/2;

CargoAPI cargo = submarket.getCargo();
cargo.addItems(CargoAPI.CargoItemType.FIGHTER_CHIP, spec.getId(), count);
}
}

protected void addHullModsMintier(int maxTier, int minTier, int num) {

CargoAPI cargo = getCargo();
for (CargoStackAPI stack : cargo.getStacksCopy()) {
//if (stack.isModSpecStack()) {
if (stack.isSpecialStack() && stack.getSpecialDataIfSpecial().getId().equals(Items.MODSPEC)){
cargo.removeStack(stack);
}
}

WeightedRandomPicker<HullModSpecAPI> picker = new WeightedRandomPicker<HullModSpecAPI>(itemGenRandom);
for (String id : submarket.getFaction().getKnownHullMods()) {
//if (Global.getSector().getCharacterData().knowsHullMod(id)) continue;
HullModSpecAPI spec = Global.getSettings().getHullModSpec(id);
if (spec.isHidden()) continue;
if (spec.isAlwaysUnlocked()) continue;
if (spec.getTier() > maxTier) continue;
if (spec.getTier() < minTier) continue;
picker.add(spec, spec.getRarity());
}

for (int i = 0; i < num; i++) {
HullModSpecAPI pick = picker.pickAndRemove();
if (pick == null) continue;

String id = pick.getId();
if (cargoAlreadyHasMod(id)) continue;

if (Global.getSector().getPlayerFaction().knowsHullMod(id)) continue;

//cargo.addItems(CargoItemType.MOD_SPEC, id, 1);

cargo.addItems(CargoAPI.CargoItemType.SPECIAL, new SpecialItemData(Items.MODSPEC, id), 1);
}

}
}
[close]
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24127
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5648 on: November 12, 2019, 09:01:02 AM »

I'm not actually seeing anything wrong in your code, looks good to me, including setting sinceSWUpdate = 0f; when you actually do update. Are you running in an IDE? If so I'd suggest trying to run it with a debugger if possible, or at least add some logging. Just looking at the code, nothing jumps out as a problem.
Logged

Sinosauropteryx

  • Captain
  • ****
  • Posts: 262
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5649 on: November 12, 2019, 09:06:07 AM »

Not stat blocks, specifically, but you can add custom text with highlights, like vanilla does for some weapons (Devastator, Sabot, Ion Cannon, etc).
Okay, cool.

Quote
Hmm - WeaponAPI.getCooldown()/getCooldownRemaining()? Or are those insufficient?
Those return the cooldown of the weapon (chargedown column in .csv), not the reload progress of the ammo. Come to think of it, though, I can time it manually.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24127
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5650 on: November 12, 2019, 09:20:44 AM »

Ahh, apologies, I didn't catch that was what you meant. Yeah, currently that's not directly exposed.
Logged

prav

  • Captain
  • ****
  • Posts: 395
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5651 on: November 12, 2019, 10:59:25 AM »

I'm not actually seeing anything wrong in your code, looks good to me, including setting sinceSWUpdate = 0f; when you actually do update. Are you running in an IDE? If so I'd suggest trying to run it with a debugger if possible, or at least add some logging. Just looking at the code, nothing jumps out as a problem.

I figured it out - this is a problem with how I'm applying the industry that adds the submarket. Every time I was entering the screen the industry was getting Unapplied and then Applied again, refreshing the stock. At least, I think that's what's going on, since commenting out the unapply code fixed the refreshing.

Speaking of submarket-adding industries, does anyone know of any intercompatability problems associated with them? Right now I can have four+storage on a market, (Open, Lab, Military, Black), which seems to work fine but I'm wondering how that interacts with other mods.
« Last Edit: November 12, 2019, 11:04:14 AM by prav »
Logged

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5652 on: November 12, 2019, 12:42:47 PM »

I got a problem with my custom fighter AI for my drones, i only noticed recently that ship.beginLandingAnimation(carrier); does not remove the ship (fighter) and i have to call the land() manually
I know how to get the list of bays from the carrier
Code
List<FighterLaunchBayAPI> bays = carrier.getLaunchBaysCopy();
, but how do i get the right bay for the fighter, do i just pick a random one? Also how does it work with ships that get converted hangars and do not have bays naturally?

-edit-
Found it:
Code
ship.getWing().getSource().getLandingLocation(ship)
« Last Edit: November 13, 2019, 05:40:10 AM by Ed »
Logged
Check out my ships

Cabbs

  • Ensign
  • *
  • Posts: 24
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5653 on: November 12, 2019, 12:52:33 PM »

I have a question of mod/rules compatibility - Is it sensible for me to replace the default vanilla "marketOptionCommDir" rule with an identical rule that contains an additional FireAll for my own rule/script, as a means of integrating a simple mod? This works fine with Nex, for reference.

Simply put I am adding an NPC based on current colony industry, and simply executing a couple of boolean checks every time the player opens the Comms Directory seems to be the least technical/simplest way of managing whether the NPC should be present. 

I do not want to try and program additional behaviour for when you manually build industry or remove it, lose a market etc, as I assume this would open up more compatibility problems and be difficult for my tiny java brain.

Is this idea bonkers? or is it possible to have a new script slot in and execute with the 'OpenCommDirectory' script without replacing anything?
Logged

Ed

  • Captain
  • ****
  • Posts: 442
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5654 on: November 12, 2019, 02:55:36 PM »

How do i get the Peak Performance duration of a ship?
Logged
Check out my ships
Pages: 1 ... 375 376 [377] 378 379 ... 710