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 ... 486 487 [488] 489 490 ... 706

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

SirHartley

  • Global Moderator
  • Admiral
  • *****
  • Posts: 839
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7305 on: April 20, 2021, 02:50:38 AM »

Alright, so I got an Industry that can change its upgrade dynamically (including into most every vanilla building).
The goal is to seed this thing on worlds with ruins, and have it be "repairable" into another building at half cost/time.

Is there a way to override upgrade cost and time for the specific upgrade instance?


Edit - successfully circumvented the issue, all is well!
« Last Edit: April 20, 2021, 04:54:07 AM by SirHartley »
Logged

Zudgemud

  • Commander
  • ***
  • Posts: 225
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7306 on: April 20, 2021, 08:22:47 AM »

Is there any easy way of making a ship system spawn a drone at a target location instead of from the ship's hull?

I basically want to spawn a drone/autonomous ship like one places a doom mine.

I'm not sure if there's  an elegant-er way of doing it, but at a minimum you could probably have a script that detects when the drone spawns and moves it wherever you like.

Sounds like you might want to check out Global.getCombatEngine().getFleetManager().spawnShipOrWing()

Thanks for the answers, more complicated than I would like but I will look into it.
« Last Edit: April 20, 2021, 08:24:24 AM by Zudgemud »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7307 on: April 20, 2021, 12:03:03 PM »

Way to modify value of exploration missions?
Like derelict/station scan or surveying a planet?

<checks> these look like they're actually hardcoded; apologies. The only way to modify their value would be to provide an alternate implementation of them. I should really extract the reward parameters at some point...
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 #7308 on: April 20, 2021, 07:57:53 PM »

Is getNumFighterBays(FleetMemberAPI data) from BaseSkillEffectDescription called anywhere in the source code outside of skills?

Use case for context:
Spoiler
I'm extending BaseSkillEffectDescription for my TC to do the following: (among other things)

When calculating the number of fighter bays to match against the total bay threshold, I want to skip any ships that are not carriers or have built in bays - similar to how the code already skips mothballed ships in the calculation.

The problem is that getNumFighterBays(FleetMemberAPI data) is a static method and so cannot be directly overridden by my child class due to java's rules on polymorphism.

I can circumvent this by overloading the method (I think anyway I haven't tried) or more simply/safely creating my own private method in my child class to do the same thing and call that method in the overridden non-static methods of the super class instead.

When viewing usages of getNumFighterBays(FleetMemberAPI data) I only see two and both are on the table to be overridden. My potential problem could be if that method has other calls obscured in the source code that could break things or return unexpected results somehow... though to be honest I can't quite think of a scenario in which that would happen.

Anyway, just trying to play it safe or at the very least know what I am getting myself into, heh.
[close]
Logged

Sarissofoi

  • Captain
  • ****
  • Posts: 405
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7309 on: April 21, 2021, 01:58:06 AM »

Way to modify value of exploration missions?
Like derelict/station scan or surveying a planet?

<checks> these look like they're actually hardcoded; apologies. The only way to modify their value would be to provide an alternate implementation of them. I should really extract the reward parameters at some point...

Haka

  • Ensign
  • *
  • Posts: 21
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7310 on: April 21, 2021, 09:19:28 PM »

I've got a ship system that is meant to functionally turn a capitol carrier into a deployable mobile station, but i'm wondering if there is ANY existing AI that would make it move to a more populated area before deploying, instead of activating it immediately at the back of the map and sitting there. At the moment it is a pure toggle (Unlimited Duration) with a short but non-instant start-up and a considerable cooldown.

Just wondering if there's anything existing that would work or if i'm going to have to learn how to do a custom AI.
Logged

Commonwheat

  • Ensign
  • *
  • Posts: 9
  • big stupid
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7311 on: April 22, 2021, 09:14:54 AM »

where can i take a look at the BURN_DRIVE aiType script? or other ship system aiTypes for that matter
i want to do a custom AI because a ship system i have just won't work with any of the existing ones i tried in the hands of the AI, so i wanted to take a look at how some of the existing AIs work as reference but i just can't find them
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 #7312 on: April 22, 2021, 03:38:38 PM »

I've got a ship system that is meant to functionally turn a capitol carrier into a deployable mobile station, but i'm wondering if there is ANY existing AI that would make it move to a more populated area before deploying, instead of activating it immediately at the back of the map and sitting there. At the moment it is a pure toggle (Unlimited Duration) with a short but non-instant start-up and a considerable cooldown.

Just wondering if there's anything existing that would work or if i'm going to have to learn how to do a custom AI.

You're probably going to have to write a custom AI. I can get you started a bit though.

1) Create a script that extends ShipSystemAIScript and provide an implementation of the "advance" method. This method runs roughly every frame, so you will need to set up an IntervalUtil to track how often the script is run. This will save on performance.

2) Point your ship system AI to the new script.

3) In the script, determine what to analyze in order to determine whether to use the system. LazyLib's CombatExtensionsKit has a method to get all enemy ships within a range that you can determine. The higher the range the more iterations so I would be prudent for performance. I set up a rudimentary weight system to determine how threatening the ships are based upon their deployment cost. The system also weights by hullsize so that capitals are considered a greater threat than frigates. Here is an example: (Keep in mind that copy pasting this won't work out of the box. You will have to adjust things and create your own implementation. This is just for a general reference to start.)

Spoiler
    private static boolean assessNearbyThreats(ShipAPI ship, ShipwideAIFlags flags, float noVentDuration) {

        List<ShipAPI> shipList = CombatExtensionsKt.getNearbyEnemies(ship, nearbyShipAssessmentRange);
        double weight = 0;
        for(ShipAPI enemyShip : shipList) {
            switch (enemyShip.getHullSize()) {
                case FIGHTER:
                    break;
                case FRIGATE:
                    weight += (frigateWeight * enemyShip.getMutableStats().getSuppliesToRecover().getBaseValue());
                    break;
                case DESTROYER:
                    weight += (destroyerWeight * enemyShip.getMutableStats().getSuppliesToRecover().getBaseValue());
                    break;
                case CRUISER:
                    weight += (cruiserWeight * enemyShip.getMutableStats().getSuppliesToRecover().getBaseValue());
                    break;
                case CAPITAL_SHIP:
                    weight += (capitalWeight * enemyShip.getMutableStats().getSuppliesToRecover().getBaseValue());
                    break;
                default:
                    break;
            }
        }
        if (weight >= weightThreshold) {
            flags.setFlag(ShipwideAIFlags.AIFlags.DO_NOT_VENT, noVentDuration);
            flags.setFlag(ShipwideAIFlags.AIFlags.KEEP_SHIELDS_ON, noVentDuration);
            if (LOG_INFO) {
                DecimalFormat round = new DecimalFormat("#.##");
                LOG.info("Threat assessment returned true. NearbyFleetStrength: " + Double.valueOf(round.format(weight))
                        + " ---- Ship won't vent flux AI flag: " + flags.hasFlag(ShipwideAIFlags.AIFlags.DO_NOT_VENT)
                        + " ---- Ship keeps shields up AI flag: " + flags.hasFlag(ShipwideAIFlags.AIFlags.KEEP_SHIELDS_ON));
            }
            return true;
        } else {
            if (weight >= (weightThreshold / weightThresholdNoVentDivisor)) {
                flags.setFlag(ShipwideAIFlags.AIFlags.DO_NOT_VENT, noVentDuration);
            }
            if (weight >= (weightThreshold / weightThresholdKeepShieldsRaisedDivisor)) {
                flags.setFlag(ShipwideAIFlags.AIFlags.KEEP_SHIELDS_ON, noVentDuration);
            }
            if (LOG_INFO) {
                DecimalFormat round = new DecimalFormat("#.##");
                LOG.info("Threat assessment returned false. NearbyFleetStrength: " + Double.valueOf(round.format(weight))
                        + " ---- Ship won't vent flux AI flag: " + flags.hasFlag(ShipwideAIFlags.AIFlags.DO_NOT_VENT)
                        + " ---- Ship keeps shields up AI flag: " + flags.hasFlag(ShipwideAIFlags.AIFlags.KEEP_SHIELDS_ON));
            }
            return false;
        }
    }
[close]

This AI isn't a toggle and I also track other things like hull damage, etc, so yours will definitely look different. My advice is to measure nearby enemies and perform a threat assessment like above, and then when the value falls below the assessment threshold you would toggle the system back to the carrier. That's just what I would do though. You might have more nuanced ideas and it's pretty fun to play around with use cases in my experience. Also you can ignore the AI flag part of the code since that is the AI making a determination about whether to vent or keep its shields up based upon a lower threshold than system activation.

4) When your above implementation of the script returns true, first check if the ship is in station mode (to prevent infinite toggling) and if it isn't - toggle the system using: ShipAPI.useSystem();

5) When your implementation of the script returns false (threats have left or been destroyed), check if the ship is in carrier mode and if not, toggle the system.

That's a very rough overview of how I would approach what you are trying to do. The extra details you will need will have to come from trial and error.  :)

Hope that helps!

where can i take a look at the BURN_DRIVE aiType script? or other ship system aiTypes for that matter
i want to do a custom AI because a ship system i have just won't work with any of the existing ones i tried in the hands of the AI, so i wanted to take a look at how some of the existing AIs work as reference but i just can't find them

I think the only example that is available is the FastMissileRacksAI under shipsystems\scripts\ai but that will get you started on the basics of how to set up an AI in the first place, and then you can create your own.

It probably doesn't need to be said that AI is very complicated. My use case is essentially "Ship in trouble? Activate super system!" and the AI to perform that relatively simple analysis is like 500 lines of code with a fair amount of moving parts.

My advice to you and the above poster - Log log log! It will save you a lot of time. ;D
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7313 on: April 22, 2021, 04:19:52 PM »

Is getNumFighterBays(FleetMemberAPI data) from BaseSkillEffectDescription called anywhere in the source code outside of skills?

It only gets called from FighterUplink, looks like.


Re: ship system AI scripts: there's:

data.shipsystems.scripts.ai.FastMissileRacksAI

That's not actually used but is there as an example that might help you get started.
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 #7314 on: April 22, 2021, 05:43:16 PM »

Is getNumFighterBays(FleetMemberAPI data) from BaseSkillEffectDescription called anywhere in the source code outside of skills?

It only gets called from FighterUplink, looks like.


Thanks good to know.
Logged

Flacman3000

  • Commander
  • ***
  • Posts: 202
  • A man cannot put his shaft into the unknown.
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7315 on: April 23, 2021, 12:44:55 AM »

I'm still in my infancy but I have no idea how to make a dud hull mod that does literally nothing but have text on it and an image of said icon. I was told to look at the shielded cargo holds for a solid example but after changing the name and descriptions I always got an error even after correcting obvious issues. Can anyone give me some pointers?
Logged
Ryzen 7 2700x, 1080ti, 16GB DDR4 RAM and playing SS on a SSD - Always stay ahead because when you're ahead you're rear anatomy is open to interpretation.

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7316 on: April 23, 2021, 07:38:55 AM »

I'm still in my infancy but I have no idea how to make a dud hull mod that does literally nothing but have text on it and an image of said icon. I was told to look at the shielded cargo holds for a solid example but after changing the name and descriptions I always got an error even after correcting obvious issues. Can anyone give me some pointers?
Might be easier to ask in the #modder_bootcamp channel on Discord. But first thing you do when you get an error is look at starsector.log, that'll usually identify the problem.

Fairly sure that the button won't even be clickable when it's not in an intel plugin, as by default tooltips don't process those kinds of events.
... ah, never mind that, you can call setForceProcessInput(true) so they would be.

Hmm - I don't think there's a very easy way. I think the best you could do is check for changes in its isChecked() status since that should change on each click, regardless of what kind of button it is.
So I tried doing this, but I can't figure a good way to detect when the button is pressed. When clicking on a regular button (but notably, not an AreaCheckbox), no mouse down/up event is passed to my custom panel plugin's processInput method. Thus, the plugin doesn't realize it's supposed to check the button state (specifically, call ButtonAPI.isChecked() for all buttons and compare it to the cached value).
Whether or not I call setForceProcessInput on the button's containing TooltipMakerAPI doesn't seem to affect it.

Should I just bite the bullet and do the state check in advance?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7317 on: April 23, 2021, 07:57:34 AM »

Should I just bite the bullet and do the state check in advance?

Yeah, definitely. It's not a performance concern.

(You wouldn't get the mouse up/down events passed in because they'd be .consume()'d by the button when it reacts to them, btw.)
Logged

briansd9

  • Ensign
  • *
  • Posts: 47
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7318 on: April 23, 2021, 08:13:45 AM »

Is there a way to find out after a battle (specifically, in BaseCampaignEventListener.reportPlayerEngagement()) if there was a bounty on the enemy fleet? Looked in PersonBountyIntel and related classes but could not find any reference to the bounty target.

Checking the enemy CampaignFleetAPI.getEventListeners() for instances of MilitaryCustomBounty, PirateSystemBounty, etc. seems like an option, but it does not feel quite proper.
Logged

Haka

  • Ensign
  • *
  • Posts: 21
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #7319 on: April 23, 2021, 09:17:21 PM »

My advice to you and the above poster - Log log log! It will save you a lot of time. ;D
You mean using starsector.log or having an editing/development log, logging progress, changes, etc. or something else?
I've definitely got a few notebooks with sketches and notes in them, but nothing as in-depth as a coder's log. I have previously kept logs for modding but so far I haven't for Starsector or for scripting.
Logged
Pages: 1 ... 486 487 [488] 489 490 ... 706