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 ... 323 324 [325] 326 327 ... 706

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

Salv

  • Lieutenant
  • **
  • Posts: 56
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4860 on: August 23, 2019, 12:37:47 PM »

Alright. Like i said, it's small matter. Thanks for the answers.
Logged

Imp0815

  • Lieutenant
  • **
  • Posts: 53
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4861 on: August 23, 2019, 04:01:01 PM »

Hi everybody,

i playing with the idea to implement a new Building. A Dockyard. On paper it sounds simple.
You build it and it Repairs(Removes) one D-Mod from a Ship every X(30?) Days. Also it halves the Supply cost of repairing your ships on the planet.
A more elaborate approach would be to open a menu to select a ship to repair. But this seems not possible with my knowledge.
An easy approach would be to just let a script select a random ship from my Storage.
So i would go with the second approach.

As i understood so far, i need to add a new building in the industries.csv and add the script in the "plugin" part like data/scrips/mydockyard. Is that correct? Or do i really need to build a plugin?

If i need to build a plugin, i already searched the API and found some stuff like the StoragePlugin.java but no sight of getting or selecting a occupied slot in the storage and all the buildings under com\fs\starfarer\api\impl\campaign\econ\impl but i did not find any interactions between the industries and the storage. But there should be a function that handles the "Use Storage on Shorated" button.

I'm not very good in java that maybe a(the) problem.

Can somebody please point me in the right direction for my endeavours?
Logged
Quantity instead of precision

Vayra

  • Admiral
  • *****
  • Posts: 627
  • jangala delenda est
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4862 on: August 23, 2019, 04:50:01 PM »

... and I can therefore store data in the hullmod with the ShipVariantAPI as a key

There's only one instance of each HullModEffect *per application session*, and it doesn't go into the savefile, at any rate. I'd say as a general rule, just don't do it period. E.G. if the variant - or whatever data you store keyed off it - references the Sector somewhere down the line, bam, that's a Sector-sized memory leak when you load a game.

If you need to store stuff long-term, use Global.getSector().getMemory() or Global.getSector().getPersistentData(). It's about the same, really, as far as which to use; persistentData is just a straightforward map.

Oop. Good tip. I would want the info to persist through saves anyway, so that's double bad. But if I can store data in the memory or persistentData and key it off the ShipVariantAPI then we're all good. :)

E: On that topic, actually: What is the most persistent ship-related object to tie a dynamic campaign-level thingy that needs to be stored to? Will its ShipVariantAPI ever be changed, should I tie it to the FleetMemberAPI, etc?
« Last Edit: August 23, 2019, 05:02:27 PM by Vayra »
Logged
Kadur Remnant: http://fractalsoftworks.com/forum/index.php?topic=6649
Vayra's Sector: http://fractalsoftworks.com/forum/index.php?topic=16058
Vayra's Ship Pack: http://fractalsoftworks.com/forum/index.php?topic=16059

im gonna push jangala into the sun i swear to god im gonna do it

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4863 on: August 23, 2019, 05:32:40 PM »

sure thing, here is the file. I've tried everything and at this point its just a simple mistake i missed
Actually, I don't think you missed anything. I got your hullmod to work by using getArmorDamageTakenMult instead of getArmorBonus or getHullBonus (both of which should work afaik).

@Alex: This might be something you want to look into. I may have missed something, but it looks like hull bonus, armor bonus, and presumably other mutable stats are never actual applied to fighters. My theory is that, for fighters, you removed the application of any mutable stats not used by vanilla as an optimization. If that's the case, perhaps there should be a MutableFighterStats interface that only exposes the limited functionality.

@Imp0815: You might want to take a look at how buildings are added by this recent WIP mod, which is the only one I'm aware of that does such a thing. I can't speak to it's quality, but it should give you a good idea of how that kind of thing is put together.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4864 on: August 23, 2019, 06:12:06 PM »

E: On that topic, actually: What is the most persistent ship-related object to tie a dynamic campaign-level thingy that needs to be stored to? Will its ShipVariantAPI ever be changed, should I tie it to the FleetMemberAPI, etc?

Probably FleetMemberAPI.getId(), if you can get access to it in all the relevant places.


@Alex: This might be something you want to look into. I may have missed something, but it looks like hull bonus, armor bonus, and presumably other mutable stats are never actual applied to fighters. My theory is that, for fighters, you removed the application of any mutable stats not used by vanilla as an optimization. If that's the case, perhaps there should be a MutableFighterStats interface that only exposes the limited functionality.

Aha - what happens here is the applyEffectsToFighterSpawnedByShip() method is called after the fighter is created (hence, the ShipAPI fighter being passed in). This means that stats that are fixed at creation time - notably, armor and hull - are already set at that point. So, if one wants to modify the fighter's armor, the way to do that would be to change the damage taken by armor instead of changing the armor value. Sorry I didn't catch this earlier!
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1723
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4865 on: August 23, 2019, 08:47:06 PM »

Oh, ok. That makes sense. It's a very understandable oversight considering applyEffectsToFighterSpawnedByShip() isn't even used by vanilla.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4866 on: August 23, 2019, 08:54:22 PM »

(It's actually used by DefectiveManufactory, but iirc that's the only vanilla use case!)
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4867 on: August 23, 2019, 09:09:19 PM »

Currently giving a market the NO_DECIV_KEY memory flag also makes it not die from saturation bombardment when size <= 4 (even though the dialog text claims it's destroyed).
Could this be changed?
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 #4868 on: August 23, 2019, 10:06:32 PM »

Hey all.

Right now I have a script that spawns fleets at specific entities. If the entity is not found, it crashes the game. This is a pretty stupid question, but what I want to do is kill the script if the particular entity can't be found, without crashing the game. I'm not sure how to handle this problem, or even what the 'kill' command is to begin with. Could anyone help me out please?

Code:
Code
package data.campaign.fleets;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.*;
import com.fs.starfarer.api.campaign.econ.MarketAPI;
import com.fs.starfarer.api.impl.campaign.fleets.BaseLimitedFleetManager;
import com.fs.starfarer.api.impl.campaign.fleets.FleetFactoryV3;
import com.fs.starfarer.api.impl.campaign.fleets.FleetParamsV3;
import com.fs.starfarer.api.impl.campaign.ids.Abilities;
import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
import com.fs.starfarer.api.util.WeightedRandomPicker;
import org.lazywizard.lazylib.MathUtils;

import java.util.Random;

public class MessFleetManager extends BaseLimitedFleetManager {
public static int MESS_MAX_FLEETS = 12;

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

@Override
protected CampaignFleetAPI spawnFleet() {

SectorEntityToken spawnEntityMess = Get_Messy();
if (spawnEntityMess == null) {
return null;
}

float combat = MathUtils.getRandomNumberInRange(1, MathUtils.getRandomNumberInRange(10,
MathUtils.getRandomNumberInRange(
100, 150)));

String fleetType;
if (combat < 10) {
fleetType = FleetTypes.PATROL_SMALL;
} else if (combat < 50) {
fleetType = FleetTypes.PATROL_MEDIUM;
} else {
fleetType = FleetTypes.PATROL_LARGE;
}

MarketAPI messmarket = Global.getFactory().createMarket(String.valueOf((new Random()).nextLong()),
String.valueOf((new Random()).nextLong()), 5);

FleetParamsV3 params = new FleetParamsV3(
null, // market
spawnEntityMess.getLocation(), // location
"mess", // fleet's faction, if different from above, which is also used for source market picking
1.5f,
fleetType,
combat, // combatPts
0f, // freighterPts
0f, // tankerPts
0f, // transportPts
0f, // linerPts
0f, // utilityPts
0 // qualityBonus
);

LocationAPI location = spawnEntityMess.getContainingLocation();  // a star system, or hyperspace
CampaignFleetAPI fleet = FleetFactoryV3.createFleet(params);
location.addEntity(fleet);// adds our new fleet into the containing location
fleet.setLocation(spawnEntityMess.getLocation().x, spawnEntityMess.getLocation().y);// positions fleet on top of the spawn entity

if ((fleet == null) || fleet.isEmpty()) {
return null;
}


fleet.removeAbility(Abilities.EMERGENCY_BURN);
fleet.removeAbility(Abilities.SENSOR_BURST);
fleet.removeAbility(Abilities.GO_DARK);

// to make sure they attack the player on sight when player's transponder is off
fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_SAW_PLAYER_WITH_TRANSPONDER_ON, true);
fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_PATROL_FLEET, true);

fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE, true);
fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_NO_JUMP, true);

fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, spawnEntityMess, 3f + (float) Math.random() * 2f);
if ((float) Math.random() > 0.75f) {
fleet.addAssignment(FleetAssignment.RAID_SYSTEM, spawnEntityMess, 250,
"raiding around the " + spawnEntityMess.getName() + " star system");
} else {
fleet.addAssignment(FleetAssignment.RAID_SYSTEM, spawnEntityMess, 500,
"raiding the " + spawnEntityMess.getName() + " star system");
}
fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, spawnEntityMess, 20,
"returning to " + spawnEntityMess.getName());
fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, spawnEntityMess, 2f + 2f * (float) Math.random(),
"orbiting " + spawnEntityMess.getName());

return fleet;
}
protected SectorEntityToken Get_Messy() {
WeightedRandomPicker<SectorEntityToken> picker = new WeightedRandomPicker<SectorEntityToken>();
for (StarSystemAPI system : Global.getSector().getStarSystems()) {
float weight = 0f;
if (system.getName().equals("Opuntia")) continue;
float w = 11f;
if (w > weight) weight = w;

for (SectorEntityToken entity : system.getAllEntities()) {
if (entity.getId().equals("mess_station1")) {
picker.add(entity, weight);
}
}
}
return picker.pick();
}
}

*Edit: De-spoilered, as this was causing some people issues.

weedlock

  • Ensign
  • *
  • Posts: 9
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4869 on: August 24, 2019, 02:10:02 AM »

I'm a little bored of the existing player flags, and I was trying to mess around with adding more. I added a flag and a crest to the directory in core/graphics, and added some new lines to player.faction. All very cool, but is there a way to do this with a mod file so its easier to distribute? From what I read only .csv's and .json's can be merged by the game.
Logged

Imp0815

  • Lieutenant
  • **
  • Posts: 53
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4870 on: August 24, 2019, 02:58:42 AM »

I'm a little bored of the existing player flags, and I was trying to mess around with adding more. I added a flag and a crest to the directory in core/graphics, and added some new lines to player.faction. All very cool, but is there a way to do this with a mod file so its easier to distribute? From what I read only .csv's and .json's can be merged by the game.

Yes you just need to make a folder in the mods folder and copy the core folder structure with all the folders and files you edited.

For Example:
Starsector\mods\yourmod\graphics\factions\custom
To add new flags.
and
Starsector\mods\yourmod\data\world\factions\player.faction
to overwrite the original faction file.


Logged
Quantity instead of precision

SwissArmyKnife

  • Ensign
  • *
  • Posts: 7
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4871 on: August 24, 2019, 03:28:44 AM »

I'm trying to take the large cannon from Black Rock Driveyards, Solenoid, and turn it into a big old Diable flavored beam cannon. This would be easy enough but I want to retain it's animations, with it opening up on start up, freezing on say frame 4 during firing, then progressing to the end on cooldown. I'm in the weeds since beam weapons .wpn file works a little differently than projectile .wpn files do.

The sprites are easy enough but I'm unsure how the animation is handled. The original Solenoid .wpn file had lines for numFrames and framerate, and it's animtype set to MUZZLE_FLASH. Can beam weapons have muzzle flash, let alone sprite based animations? I couldn't find a vanilla example, the most indepth those got were recoil or glow effects.

I'm also not really sure what the everyFrameEffect and .java file do. I again based mine off the original Solenoid and guessed what the file was doing.

Sprites (Still need to do the turret version I know):
Spoiler
[close]

.wpn
Spoiler
Code
{
"id":"diableavionics_eldos",  # this id must match what's in the spreadsheet
"specClass":"beam",
"type":"ENERGY",
"size":"LARGE",
"displayArcRadius":1200,
"turretSprite":"graphics/da/weapons/eldos/eldos_turret00.png",
"hardpointSprite":"graphics/da/weapons/eldos/eldos_hpbarrel00.png",
"numFrames":24,
"frameRate":15,
"visualRecoil":0.0,  # the gun sprites are only used if this is non-0
"renderHints":[RENDER_BARREL_BELOW],
"turretOffsets":[30, 0],
"turretAngleOffsets":[0],
"hardpointOffsets":[50, 0],
"hardpointAngleOffsets":[0],
"barrelMode":"ALTERNATING", # or LINKED.  whether barrels fire at the same time or alternate.
"animationType":"MUZZLE_FLASH",  # NONE, GLOW, MUZZLE_FLASH, SMOKE
"muzzleFlashSpec":{"length":45.0,   # only used if animationType = MUZZLE_FLASH
   "spread":6.0,
   "particleSizeMin":1.0,
   "particleSizeRange":60.0,
   "particleDuration":1.25,
   "particleCount":63,
   "particleColor":[135,155,170,125]},
"fireSoundOne":"diableavionics_eldos_start",
"fireSoundTwo":"diableavionics_eldos_loop",
    "everyFrameEffect":"data.scripts.weapons.EldosAnimation",
}
[close]

EldosAnimation.java
Spoiler
Code
package data.scripts.weapons;

public class EldosAnimation extends BaseAnimateOnFireEffect {

    public EldosAnimation() {
        super(); // doesn't actually do anything
        setFramesPerSecond(15);
        pauseOnFrame(4);
    }
}
[close]

Thanks!

Update: Figured out most of the above by copying some stuff from Neutrino Corps Phase Cannon. Only issue now is the java file crashes Starsector on load with:
Spoiler
Code
java.lang.RuntimeException: Error compiling [data.scripts.weapons.EldosAnimation]
at com.fs.starfarer.loading.scripts.ScriptStore$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: data.scripts.weapons.EldosAnimation
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:179)
at java.lang.ClassLoader.loadClass(Unknown Source)
[close]

And here's the java file.
Spoiler
Code
// By Deathfly
package data.scripts.weapons;

import com.fs.starfarer.api.AnimationAPI;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
import com.fs.starfarer.api.combat.WeaponAPI;

public class EldosAnimation implements EveryFrameWeaponEffectPlugin {

    private final float validFrames = 13;
//    private final float animeMAXchargelvl = 0.8f;
    private float chargeLevel = 0;

    @Override
    public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
        AnimationAPI anime = weapon.getAnimation();
       
        if (anime == null){
            return;
        }
        if (!weapon.isFiring()) {
            chargeLevel = 0;
            anime.setFrameRate(-12);
            if (anime.getFrame() == 0) {
                anime.setFrameRate(0);
            }
        } else {
            if (weapon.getChargeLevel() >= chargeLevel) {
                chargeLevel = weapon.getChargeLevel();
                if (anime.getFrame() < validFrames) {
                    anime.setFrameRate(12);
                } else {
                    anime.setFrameRate(0);
                    anime.setFrame(13);
                }
            } else {
                chargeLevel = weapon.getChargeLevel();
                if (anime.getFrame() > 0) {
                    anime.setFrameRate(-12);
                } else {
                    anime.setFrameRate(0);
                    anime.setFrame(0);
                }
            }
            if (weapon.getShip().getFluxTracker().isOverloadedOrVenting()){
                weapon.setRemainingCooldownTo(weapon.getCooldown());
            }
        }
    }
}
[close]

I figured it was because the default compiler runs JDK 6 and I need JDK 7 but all the IDE guides I found were massively out of date. Tried IntelliJ IDEA and couldn't for the life of me get it to actually compile the damn jar file. Giving up until tomorrow.
« Last Edit: August 24, 2019, 06:20:17 AM by SwissArmyKnife »
Logged

Imp0815

  • Lieutenant
  • **
  • Posts: 53
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4872 on: August 24, 2019, 05:29:58 AM »


I'm also not really sure what the everyFrameEffect and .java file do. I again based mine off the original Solenoid and guessed what the file was doing.


I think everything in their fires every frame.
Logged
Quantity instead of precision

Melissia

  • Ensign
  • *
  • Posts: 2
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4873 on: August 24, 2019, 09:56:26 AM »

Is there a simple way to change the normal map size and star count, and have more star systems and such to explore?  I admit to being new to modding this game, though I have owned it and played it off and on for a long time now (since may 2013 in fact!).  I at least figured out how to install preexisting mods.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #4874 on: August 24, 2019, 11:01:27 AM »

Currently giving a market the NO_DECIV_KEY memory flag also makes it not die from saturation bombardment when size <= 4 (even though the dialog text claims it's destroyed).
Could this be changed?

Fixed!


Right now I have a script that spawns fleets at specific entities. If the entity is not found, it crashes the game. This is a pretty stupid question, but what I want to do is kill the script if the particular entity can't be found, without crashing the game. I'm not sure how to handle this problem, or even what the 'kill' command is to begin with. Could anyone help me out please?

Generally you want to check something like "if (entity == null) return null" or some such, but it depends on exactly where and with what error.

I'm a little bored of the existing player flags, and I was trying to mess around with adding more. I added a flag and a crest to the directory in core/graphics, and added some new lines to player.faction. All very cool, but is there a way to do this with a mod file so its easier to distribute? From what I read only .csv's and .json's can be merged by the game.

The .faction are json files under the hood and are treated as such as far as merging, so it should be fine.


@SwissArmyKnife: not actually sure offhand what's going on. Might be another error message somewhere earlier in the log? This sort of thing might happen if your script is doing something Janino (the compiler the game uses for loose scripts) doesn't support, or if the class doesn't have a default constructor, but none of that seems to be the problem in your code.


Is there a simple way to change the normal map size and star count, and have more star systems and such to explore?  I admit to being new to modding this game, though I have owned it and played it off and on for a long time now (since may 2013 in fact!).  I at least figured out how to install preexisting mods.

Hi - take a look here:

http://fractalsoftworks.com/forum/index.php?topic=16127.0
Logged
Pages: 1 ... 323 324 [325] 326 327 ... 706