Fractal Softworks Forum

Please login or register.

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

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

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5610 on: November 07, 2019, 01:40:15 PM »

com.fs.starfarer.api.impl.campaign.TOffAlarm is probably a pretty reasonable example.

It uses an IntervalUtil to only do its checks now and again (instead of every frame), which is the approach the game generally takes to reduce performance impact. In your case, the check is so simple it's probably not worth the extra hassle of using an interval tracker.
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 #5611 on: November 07, 2019, 01:44:40 PM »

Thanks Ill take a look!
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 #5612 on: November 07, 2019, 03:44:03 PM »

In your case, the check is so simple it's probably not worth the extra hassle of using an interval tracker.

Well I thought about this a little more and since this is faction specific I overstated the simplicity of the check at least a little bit. It has to check for the player memory boolean for each faction since the memory flag is faction specific. So in this sense it might be O(n^2) instead of O(n). Maybe I should implement the interval tracker.

A question about that:

Code

private IntervalUtil tracker = new IntervalUtil(0.05f, 0.1f);

float days = Global.getSector().getClock().convertToDays(amount);
tracker.advance(days);

if (tracker.intervalElapsed()) {
notifyNearby();
}

... impl notifyNearby() etc


Does this mean it performs the check every in game day? And it does this by converting the passed in variable "amount" to the sector clock's definition of days? So it could, in theory, be converted to in game months or cycles?
Logged

Yunru

  • Admiral
  • *****
  • Posts: 1560
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5613 on: November 07, 2019, 03:47:38 PM »

Well I thought about this a little more and since this is faction specific I overstated the simplicity of the check at least a little bit. It has to check for the player memory boolean for each faction since the memory flag is faction specific. So in this sense it might be O(n^2) instead of O(n). Maybe I should implement the interval tracker.
Why a boolean?
If you assigned each faction an integer, you'd only have to check whether the integer has changed, rather than checking every boolean.

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5614 on: November 07, 2019, 06:22:15 PM »

Well I thought about this a little more and since this is faction specific I overstated the simplicity of the check at least a little bit. It has to check for the player memory boolean for each faction since the memory flag is faction specific. So in this sense it might be O(n^2) instead of O(n). Maybe I should implement the interval tracker.
Why a boolean?
If you assigned each faction an integer, you'd only have to check whether the integer has changed, rather than checking every boolean.

Unless I'm misunderstanding something, that would require 12 separate EveryFrameScripts which defeats the purpose. What I mean is: Since faction portraits are faction specific, I have to iterate over each faction to check for that faction's lock. Its still the same processing speed regardless if I'm checking a boolean or an int the only thing that reduces the task's workload would be having a "not" check rather than a "positive" check afaik. Please correct me if not.
Logged

Yunru

  • Admiral
  • *****
  • Posts: 1560
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5615 on: November 07, 2019, 06:28:00 PM »

What I meant was surely you don't have to check which faction the player switched too each frame, just whether the player switched.

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5616 on: November 07, 2019, 07:46:28 PM »

What I meant was surely you don't have to check which faction the player switched too each frame, just whether the player switched.

Oh gotcha I understand now! I am being too general and not explaining the technical implementation. The player locks portraits based on the faction in question before the encounter that would trigger the EveryFrameScript even begins. So the check isn't for whether the player switched factions at all, but whether they:

A) Have locked player portraits on a specific faction. This is the boolean which is faction specific because it also serves as the flag to populate the dialogue to reverse back to all portraits. So because the rule that checks each flag offers faction specific dialogue to reverse it and relies on a unique faction-based check to fire the rule- it must inherently remain unique as well.

 - To your point, however, I see now another player variable- set as an int being set to 0 or 1- indicating a general all-purpose lock/not lock to player portraits- would very well serve the same function since you can't have more than one commission and so theoretically you couldn't have more than one faction's portraits locked to the player's when checking the EveryFrameScript. However:

B) No longer has a commission with that specific faction when the assumption is they originally did have one before.

- This is harder to get around since I would therefore have to determine the origin faction to check for an active commission with that faction. That is where the faction specific boolean comes into play. Unless I can just check for player.hasCommission() in general without determining faction (not sure honestly), I wouldn't be able to use the above all-purpose player variable.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5617 on: November 07, 2019, 07:48:16 PM »

Misc.getCommissionFactionId() != null

To check whether the player currently has a commission or not.

See also:
Misc.getCommissionFaction()
Misc.getCommissionIntel()
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 #5618 on: November 07, 2019, 07:53:12 PM »

Misc.getCommissionFactionId() != null

To check whether the player currently has a commission or not.

See also:
Misc.getCommissionFaction()
Misc.getCommissionIntel()

Great! That will be optimal and remain at O(n) performance. :) Thanks to you both.
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 #5619 on: November 07, 2019, 08:49:24 PM »

Here is what I have. I'll admit that I'm still not 100% familiarized with how the EveryFrameScript works, but I tried to implement the interval tracker because nothing explicit- other than the EveryFrameScript extension itself and the "advance()" method that seems to be utilized by default- indicates that it will actually be run every frame. I kept it as close the the original implementation of TOffAlarm as possible for now. If I have that portion incorrect I can remove it, but if not then I may as well keep it since this script doesn't need to be ran every frame. It could be ran every 7 days and still be within believable immersion parameters.

Does this need to link to a settings entry, mod plugin or a rule to run every frame? Or do I just need to include this in the correct jar for implementation? Thank you for any help.

Code

package archeus.campaign.everyframescripts;

import com.fs.starfarer.api.EveryFrameScript;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.util.IntervalUtil;
import com.fs.starfarer.api.util.Misc;
import archeus.rulecmd.SetPlayerPortraits;

import java.util.ArrayList;
import java.util.List;

public class CheckCommissionForPortraitLocks implements EveryFrameScript {
private IntervalUtil tracker = new IntervalUtil(0.05f, 0.1f);

public CheckCommissionForPortraitLocks() {
if (Global.getSector().getPlayerPerson().getMemory().getBoolean("$player.FactionOnlyPortraitsEnabled") && Misc.getCommissionFactionId() == null) {
resetPlayerPortraits();
}
}

public void advance(float amount) {
float days = Global.getSector().getClock().convertToDays(amount);
tracker.advance(days);


if (tracker.intervalElapsed()) {
if (Global.getSector().getPlayerPerson().getMemory().getBoolean("$player.FactionOnlyPortraitsEnabled") && Misc.getCommissionFactionId() == null) {
resetPlayerPortraits();
}
}
}


public void resetPlayerPortraits() {
SetPlayerPortraits portraits = new SetPlayerPortraits();

List<Misc.Token> params = new ArrayList<Misc.Token>();
Misc.Token token = new Misc.Token("all", null);
params.add(0, token);
portraits.execute(null, null, params, null);

Global.getSector().getPlayerPerson().getMemory().set("$player.FactionOnlyPortraitsEnabled", false);
}

public boolean isDone() {
return true;
}

public boolean runWhilePaused() {
return false;
}
}

« Last Edit: November 07, 2019, 10:57:18 PM by Morrokain »
Logged

Green Ghost

  • Ensign
  • *
  • Posts: 23
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5620 on: November 08, 2019, 01:39:34 AM »

Not sure if this is the right thread for it but, Is there way to affect the gender ratio for captains/administrators? Im using portrait mods with most of them being female so most of the males get the same faces, any way i can make most characters spawn as female?
Logged

SomeDegenerate

  • Ensign
  • *
  • Posts: 15
  • Credit to TerminalMontage on YouTube for the PfP
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5621 on: November 08, 2019, 08:01:21 AM »

How does the game fetch the tooltip for an industry? I'm running into a null pointer exception whenever I mouse over my industry; it appears I've missed something to tell the game how to make the tooltip or have left some field blank somewhere.

Thanks!
Logged
Roses are red, violets are blue. I'm complete garbage, how about you?

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5622 on: November 08, 2019, 05:31:08 PM »

Does this need to link to a settings entry, mod plugin or a rule to run every frame? Or do I just need to include this in the correct jar for implementation? Thank you for any help.

Something like;

if (!Global.getSector().hasScript(CheckCommissionForPortraitLocks.class)) {
    Global.getSector().addScript(new CheckCommissionForPortraitLocks());
}

Somewhere in ModPlugin; say in onNewGameAfterEconomyLoad().


Not sure if this is the right thread for it but, Is there way to affect the gender ratio for captains/administrators? Im using portrait mods with most of them being female so most of the males get the same faces, any way i can make most characters spawn as female?

Currently hardcoded to 50/50, sorry!

How does the game fetch the tooltip for an industry? I'm running into a null pointer exception whenever I mouse over my industry; it appears I've missed something to tell the game how to make the tooltip or have left some field blank somewhere.

Thanks!

See: BaseIndustry.createTooltip(). The exception's stack trace should also be fairly helpful in figuring out exactly what went wrong.
Logged

creature

  • Captain
  • ****
  • Posts: 400
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5623 on: November 08, 2019, 05:58:51 PM »

Not sure if this is the right thread for it but, Is there way to affect the gender ratio for captains/administrators? Im using portrait mods with most of them being female so most of the males get the same faces, any way i can make most characters spawn as female?

Currently hardcoded to 50/50, sorry!

Related to this, would there be some way to 'hack' the strings such that I could replace all instances of he/him with she/her for a specific faction?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #5624 on: November 08, 2019, 06:09:35 PM »

I don't *think* so. Some of the strings are generated using CoreRuleTokenReplacementGeneratorImpl (and so could probably be overridden), but a number aren't. The easiest thing to do would probably be to have a script that replaces male captains/fleet commanders/etc with female - say, in a custom fleet inflater, or something else depending on the circumstances.
Logged
Pages: 1 ... 373 374 [375] 376 377 ... 710