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 ... 48 49 [50] 51 52 ... 706

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

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #735 on: August 31, 2013, 09:19:57 AM »

Thought this may be useful:

How to get a ShipAPI from a FleetMemberAPI:
Code
        ListIterator Fleetships = FleetID.getFleetData().getMembersListCopy().listIterator();
        while(Fleetships.hasNext())
        {
            FleetMemberAPI fmember = (FleetMemberAPI)Fleetships.next();
            MutableShipStatsAPI stats = fmember.getStats();
            ShipAPI ship = (ShipAPI) stats.getEntity();
}

not 100% sure it works, if it does, i wish i had found out alot sooner.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #736 on: August 31, 2013, 09:28:39 AM »

It doesn't. Rather, it only does if you're calling stats.getEntity() from within combat. A ShipAPI doesn't exist for a FleetMember in the campaign.

Is there any way to get at what a ship's armed with?  I'm working on a ship system AI; the system in question primarily benefits energy weapons, but the ship has universal slots - I'd like the AI to react intelligently to noticing that it has missiles or ballistics instead of energy weaponry.  (This one I'm pretty sure isn't doable until 0.6, but hey, worth asking right?)

I'm not exactly sure what's in it as of 0.54.1a, but take a look at ShipAPI.getVariant(). That may have what you need. Also, is there a ShipAPI.getAllWeapons()? In any event, this will definitely be possible in 0.6a.

... actually, take a look at data.shipsystems.scripts.ai.FastMissileRacksAI. That's doing pretty much what you are talking about.
Logged

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #737 on: September 03, 2013, 09:40:30 AM »

Ive hit a bump here, so far theres alot of work done into making a possible Utilitymod, that adds dynamic starsystem gen, an mining system, more control over each element of a starsystem, factiondata and products, product schematics (allows adding possible cargo creation using 2 or 3 different cargos) and hopefully a economy.
https://bitbucket.org/silentstormpt/starsector-utility-mods/commits/all

Question how would you create a productSchematic class that by providing x productentities will result in a specific productentity?
https://bitbucket.org/silentstormpt/starsector-utility-mods/src/8b77fdbc22bd2db1bcfeec97dcb17f1a26c64c01/data/scripts/world/economy/ProductSchematic.java?at=default

Btw the productEntity is suppose to save info for a certain cargo, so you can see it as a model that saves all the info on that cargo, provided by a CSV or JSON file, so any mod that provides that info can create their specific unique products and schematics, that can be used to create that cargo. For example:

everyday i generate X amount of productEntity.createCargo(yourminingship.getCargo(), productEntity, Quantity);

That productEntity can be "gold" or any type of product you want used as a mineral.

Disclaimer: this is all pretty much work in progress and should only work once 0.6a arrives and i can finally set all the missing methods into this "puzzle"
« Last Edit: September 03, 2013, 09:43:55 AM by silentstormpt »
Logged

Ravendarke

  • Captain
  • ****
  • Posts: 276
  • Nemesis
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #738 on: September 08, 2013, 02:40:24 PM »

What is in your opinion most effective way (resource wise) to convert specific beam weapon to deal hard flux instead of soft?
Logged

FlashFrozen

  • Admiral
  • *****
  • Posts: 988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #739 on: September 08, 2013, 03:23:42 PM »

Lazy wizard has a implementation that changes beam soft flux damage to hard here

I don't know if this suggestion has been made yet- only read through the last few pages, but here is a possible idea that could balance out the problems with using beams to kite while still giving them killing power.  What if beams did full DPS throughout their range, but scaled from 100% hard flux at zero range to 100% soft flux at max range?  (or maybe something like 50% soft at 20% max range and lower to 100% soft at 80% max range and higher).  You could even put in a slight color or gamma gradient over the beam's range so there is visual feedback on whether you are in the soft or hard flux range bands. 

Thus - if you try to kite with your superior range you're only doing soft flux, but if you want to abuse your manly tri-tac shields you can fly in close for some hard flux damage, but risk the return fire.

I liked this idea so much I decided to try it out. Here's a small test mod that gives all vanilla beams 0-100% hard flux based on distance to the target (requires LazyLib).

I've only tested it briefly, but the most noticeable effect is that the famed Disco Paragon has gone from "able to kill anything smaller than it" to "able to kill anything, period" (including taking on two Conquests and an Onslaught simultaneously). I'll try making a version using the other variant you mentioned, as I think that might be more balanced. :)

http://www.mediafire.com/download/rt9b5lirjogrs3h/Alternate_Beam_Mechanics.zip
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #740 on: September 08, 2013, 03:52:18 PM »

I believe there was a bug in that version of the code. Here's the version I currently have in my sandbox project:

Code
package data.scripts.weapons;

import com.fs.starfarer.api.combat.BeamAPI;
import com.fs.starfarer.api.combat.BeamEffectPlugin;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.FluxTrackerAPI;
import com.fs.starfarer.api.combat.ShieldAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.WeaponAPI;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.lazylib.combat.DefenseType;
import org.lazywizard.lazylib.combat.WeaponUtils;

public class HardFluxBeam implements BeamEffectPlugin
{
    @Override
    public void advance(float amount, CombatEngineAPI engine, BeamAPI beam)
    {
        if (beam.getDamageTarget() instanceof ShipAPI)
        {
            ShipAPI target = (ShipAPI) beam.getDamageTarget();
            ShieldAPI shield = target.getShield();
            if (shield != null && shield.isWithinArc(beam.getTo()))
            {
                WeaponAPI wep = beam.getWeapon();
                float damage = WeaponUtils.calculateDamagePerSecond(wep,
                        target, DefenseType.SHIELD) * amount;

                // Hard flux dealt is based on distance to target
                float hardFluxRatio = 1f - (MathUtils.getDistance(
                        beam.getFrom(), beam.getTo()) / wep.getRange());
                float softFlux = damage * (1f - hardFluxRatio);
                float hardFlux = damage * hardFluxRatio;


                // Undo the vanilla flux damage, add our custom damage
                FluxTrackerAPI flux = target.getFluxTracker();
                flux.decreaseFlux(damage);
                flux.increaseFlux(softFlux, false);
                flux.increaseFlux(hardFlux, true);
            }
        }
    }
}

It's not 100% accurate, unfortunately. Guessing how much damage is being dealt is complicated, and beam damage especially so.
« Last Edit: September 08, 2013, 04:04:07 PM by LazyWizard »
Logged

Ravendarke

  • Captain
  • ****
  • Posts: 276
  • Nemesis
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #741 on: September 08, 2013, 04:59:32 PM »

I like that idea with range, really, gave me a idea... using it (for one specific weapon) not just for hard/soft flux ration but for dmg overall, while inverted (longer range = more dmg). Or it could be even used to create weapon with deadzone.. doing lot of dmg on close range, lot of dmg on max range but almost non in middle.. hmm.. anyway thanks a lot :)
Logged

MShadowy

  • Admiral
  • *****
  • Posts: 911
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #742 on: September 09, 2013, 09:19:16 PM »

Alrighty, so, the code I'm having trouble with at the moment is this ai script, based off of the ReflectorAI from BRDY.  Honestly, it feels like the problem shouldn't be that hard to deal with, except every time I end up calling up the autocomplete in netbeans the program hangs, which is kind of annoying.

Code
package data.shipsystems.scripts.ai;

import com.fs.starfarer.api.combat.MutableShipStatsAPI;
import com.fs.starfarer.api.combat.CombatEngineAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.ShipSystemAIScript;
import com.fs.starfarer.api.combat.ShipSystemAPI;
import com.fs.starfarer.api.combat.ShipwideAIFlags;
import java.util.Iterator;
import org.lwjgl.util.vector.Vector2f;
import org.lazywizard.lazylib.combat.*;
import org.lazywizard.lazylib.MathUtils;

public class ms_siegemodeAI implements ShipSystemAIScript {
    private ShipSystemAPI system;
    private ShipAPI ship;

    @Override
    public void init(ShipAPI ship, ShipSystemAPI system, ShipwideAIFlags flags, CombatEngineAPI engine)
    {
        this.ship = ship;
        this.system = system;
    }

    @Override
    public void advance(float amount, MutableShipStatsAPI stats, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target)
    {
        float goLive = 1200f; //the AI needs to know (roughly) how big the range of our weapons boost is.
        float fuzzyLogic = 0f; //set our logic counter to 0
        
        int ships = 0;
        ShipAPI ship_tmp;
    
        for (Iterator iter = CombatUtils.getCombatEngine().getShips().iterator();
                iter.hasNext();)
        
        {
            ship_tmp = (ShipAPI) iter.next();
            ship_tmp.getMutableStats();
                
            if ((ship_tmp.getOwner() != ship.getOwner()) && (MathUtils.getDistance(ship_tmp, ship) >= (goLive * 1.05f)))
            { //Check hostility and range
                    fuzzyLogic += ship_tmp.getFluxCapacity(); //Watch out for lots of Flux  --  This is the first line bearing an error.
                    fuzzyLogic += ship_tmp.getMaxHitpoints(); //And big hitpoint pools - we can generally presume that vessel with both/either would require sieging
                    fuzzyLogic -= (ship_tmp.getMaxSpeed() * 2.5f); //Of course, we don't really want to hold still when we're dealing with fast targets   --  And this is the second.
            }
        }
        float fluxLevel = ship.getFluxTracker().getFluxLevel();
                
        if (fuzzyLogic > 5000f && !system.isActive() && fluxLevel < 0.95f) {
            //compare our counter to a magic number, make sure the system is already off, and that our flux level isn't too high
            ship.useSystem();
        } else if ((fuzzyLogic <= 2000f || fluxLevel >= 0.95f || goLive >= goLive * 1.15f) && system.isActive()) {
            //if there is little-to-no threat OR if our flux level is too high OR if the enemies are far enough away, turn the system off if it is currently active
            ship.useSystem();
        } else { return; }
    }

}

I've been playing around with MutableShipStatsAPI to see if that would work, but it doesn't seem to be playing nicely with ship_tmp.  Alas.
« Last Edit: September 09, 2013, 09:26:25 PM by MShadowy »
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #743 on: September 09, 2013, 09:26:55 PM »

You're looking for ship_tmp.getFluxTracker().getMaxFlux(), ship_tmp.getMaxHitpoints(), and ship_tmp.getMutableStats().getMaxSpeed().getModifiedValue().

Quote
Honestly, it feels like the problem shouldn't be that hard to deal with, except every time I end up calling up the autocomplete in netbeans the program hangs, which is kind of annoying.

Try following the instructions here to clear Netbean's cache and see if that helps with the hanging issues.


Edit: also, you'll want to change
Code
public void advance(float amount, MutableShipStatsAPI stats, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target)
to
Code
public void advance(float amount, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target)
« Last Edit: September 09, 2013, 09:32:33 PM by LazyWizard »
Logged

MShadowy

  • Admiral
  • *****
  • Posts: 911
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #744 on: September 09, 2013, 09:46:22 PM »

Unfortunately clearing the cache hasn't seemed to resolve the issue with netbeans.

At least the code is working pretty well now, though.  Thanks for your help, Lazy!
Logged

Erick Doe

  • Global Moderator
  • Admiral
  • *****
  • Posts: 2489
  • "Pretty cunning, don't you think?"
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #745 on: September 13, 2013, 07:16:01 AM »

I completely missed this:

Will we be able to assign specific graphics to stations in 0.6a?

I realise that we can do this now, but as of now it overwrites the graphics of all stations.

To elaborate my question: can we make station graphics faction specific in 0.6a?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #746 on: September 13, 2013, 01:53:18 PM »

Will we be able to assign specific graphics to stations in 0.6a?

I realise that we can do this now, but as of now it overwrites the graphics of all stations.

To elaborate my question: can we make station graphics faction specific in 0.6a?

No - it's definitely on my list, just couldn't get to it. Hoping to sneak it in in 0.6.1a.
Logged

Verrius

  • Captain
  • ****
  • Posts: 369
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #747 on: September 13, 2013, 11:03:35 PM »

Can somebody explain to me in a nutshell, what Jars are, and how they work with Starsector? It seems like a pretty standard Java thing. Funnily enough I don't know much about Java.

(I'm asking because it seems like you need them to get around generics are something. It's hard to explain because I'm realizing just now how little I know about Java.)

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #748 on: September 14, 2013, 01:18:58 AM »

Can somebody explain to me in a nutshell, what Jars are, and how they work with Starsector? It seems like a pretty standard Java thing. Funnily enough I don't know much about Java.

(I'm asking because it seems like you need them to get around generics are something. It's hard to explain because I'm realizing just now how little I know about Java.)

Just a note - you don't actually need generics, they just make life slightly easier. You can code pretty much anything without them that you could using them. :)

Anyway, the explanation:

Most mods implement their scripts as loose java files in their mod folders. When the game launches, it finds all these scripts and passes them to Janino. Janino is a very small, very fast compiler that Starfarer uses to compile scripts. While it is fast, the downside is that it doesn't support the full list of Java language features, generics being foremost among that list.

A jar is basically an archive (like a zip or rar) that contains compiled java code (.class files), 'compiled' meaning it's been translated into a form the computer can understand. Since the code in a jar is already readable by the Java VM, the game can load these classes directly into memory, bypassing Janino and its restrictions.

If you are already using an IDE you should have an easy time creating a jar - in NetBeans it'd be Clean and Build (Shift+F11), and you'd find the jar in your NetBeans project folder inside the dist directory. Just put that jar somewhere in your mod folder, then add a line to your mod_info.json telling the game where to find it.

For example, LazyLib's compiled code is stored in jars/LazyLib.jar. So it requires the following line in its mod_info.json:
Code
    "jars":["jars/LazyLib.jar",],

There is one pitfall you have to watch out for. Unless Alex has changed it in .6a, scripts in data/scripts/plugins need to be outside a jar to be automatically loaded by the game.


Again, you don't need to know anything about using generics or jars to write a mod. Just create mods the way you are most comfortable and everything will continue to work. :)
Logged

Cycerin

  • Admiral
  • *****
  • Posts: 1665
  • beyond the infinite void
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #749 on: September 14, 2013, 06:39:04 AM »

How should I implement custom engine sounds in a similar way to the core game without ruining compatibility with other mods?

Code
	"engine_loop":{
"sounds":[
{"file":"sounds/BR/fx/brdyshipsounds/blackrockengine_frig.ogg","pitch":1,"volume":1},    # index:  14
{"file":"sounds/BR/fx/brdyshipsounds/blackrockengine_frig.ogg","pitch":1,"volume":1}, # index:  15
{"file":"sounds/BR/fx/brdyshipsounds/blackrockengine_destroyer.ogg","pitch":1,"volume":1},    # index:  16
{"file":"sounds/BR/fx/brdyshipsounds/blackrockengine_cruiser.ogg","pitch":1,"volume":1},  # index:  17
{"file":"sounds/BR/fx/brdyshipsounds/blackrockengine_capital.ogg","pitch":1,"volume":1},    # index:  18
],

"BLACKROCKHULL":{"sounds":[15,16,17,18,19], "pitch":1, "volume":1},
"FIGHTER":{"sounds":[15], "pitch":1, "volume":0.5},
"FRIGATE":{"sounds":[16], "pitch":0.9, "volume":0.6},
"DESTROYER":{"sounds":[17], "pitch":0.9, "volume":0.7},
"CRUISER":{"sounds":[18], "pitch":0.9, "volume":0.75},
"CAPITAL_SHIP":{"sounds":[19], "pitch":1, "volume":0.8},
},

As far as I can see, if I use an index from 0 and out it uses core sounds. But if a different mod tried to call the same list entries as the ones I'm using, would there be a conflict? Can I do this in a more... isolated fashion?
Logged
Pages: 1 ... 48 49 [50] 51 52 ... 706