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 ... 250 251 [252] 253 254 ... 706

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

bananana

  • Commander
  • ***
  • Posts: 226
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3765 on: January 18, 2018, 01:32:40 AM »

My recommendation is to instead run AIUtils.getNearbyAllies and then manually run a loop to see which is closest. You'll have to input a range, but if you want it global just input a really high one. This would allow you to ignore modules through the previously mentioned "if" function, though it is not quite as compact code-wise.
then i face another problem, since i keep getting "assignment conversion error" whenever i am trying to make a list of targets.  probably due to not having a .jar.
thanks for the help anyway
« Last Edit: January 18, 2018, 01:39:56 AM by passwalker »
Logged
Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
i do NOT want to see my name appear in the credits section of any published mod and will consider it a personal insult.

Nicke535

  • Commander
  • ***
  • Posts: 240
  • Degenerate Core
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3766 on: January 18, 2018, 02:54:38 AM »

My recommendation is to instead run AIUtils.getNearbyAllies and then manually run a loop to see which is closest. You'll have to input a range, but if you want it global just input a really high one. This would allow you to ignore modules through the previously mentioned "if" function, though it is not quite as compact code-wise.
then i face another problem, since i keep getting "assignment conversion error" whenever i am trying to make a list of targets.  probably due to not having a .jar.
thanks for the help anyway

Are you attempting to make a List() or an ArrayList()? An ArrayList() should still work without the .jar (this is what I run on my AI scripts, which are not compiled).

bananana

  • Commander
  • ***
  • Posts: 226
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3767 on: January 18, 2018, 04:39:31 AM »

i think i set up the IDEA so thee problem is obsoleetee now.

good suggestion, but too late.

thanks anyway.
Logged
Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
i do NOT want to see my name appear in the credits section of any published mod and will consider it a personal insult.

Snrasha

  • Admiral
  • *****
  • Posts: 705
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3768 on: January 24, 2018, 11:03:39 AM »

Spoiler

[close]
Hello, i have somes problems with ship with module.
No problem when this is the player who out this ship, but the ennemi do not spawn the module like you can see on this beautiful screenshoot taken per Kusar.

I have found nothing wrong on that, someone have a idea? Thank you!
« Last Edit: January 24, 2018, 01:55:04 PM by Snrasha »
Logged
I am pretty bad on english. So, sorry in advance.

Gladiator Society
Add battle options on Com Relay/ Framework for modders for add their own bounty.

Sanguinary Autonomist Defectors A fan-mod of Shadowyard.

Tartiflette

  • Admiral
  • *****
  • Posts: 3529
  • MagicLab discord: https://discord.gg/EVQZaD3naU
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3769 on: January 24, 2018, 01:50:52 PM »

Does it has the SHIP_WITH_MODULE tag?
Logged
 

Snrasha

  • Admiral
  • *****
  • Posts: 705
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3770 on: January 24, 2018, 01:54:54 PM »

Does it has the SHIP_WITH_MODULE tag?

Yep, he have not., this is fun to lose 1 hours to check the difference with my another ship who work and see any difference:
Spoiler
[close]

Thank you xD
Logged
I am pretty bad on english. So, sorry in advance.

Gladiator Society
Add battle options on Com Relay/ Framework for modders for add their own bounty.

Sanguinary Autonomist Defectors A fan-mod of Shadowyard.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3771 on: January 24, 2018, 06:36:24 PM »

Was trying to write a Mission that would allow a player to renounce their Commission without having to do anything illegal to lower their Reputation with the Faction.

I'm really confused about how the Mission structure works here and what, exactly, I'm supposed to do to alter this. 

The problem here is that there is this trifold structure:

FactionCommissionMissionEvent appears to control what happens once the "Accept" button is pressed... but does not alter whether or not the button appears in the Missions boards.

FactionCommissionMission appears to control whether the Mission is displayed in the UI, but doesn't control what happens when we attack Bounties, neutral parties, etc., etc.

Both of these appear to be hard-referenced by CoreLifeCyclePlugin, as well, which means that modification is... difficult, because that touches so much other code.

It's also very unclear how, exactly, we're supposed to inject Missions into the UI.

So...

1.  How do we detect whether a given Mission is currently active?
2.  How do we inject a Mission into the UI (i.e., offer to annul the Commission) if 1 is true?
3.  Can we invoke public code in that other Mission to end it?

That seems like the route to success here.  It's just a little messy under the hood and it's a little hard to see what to do with this system.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3772 on: January 25, 2018, 03:38:33 AM »

As you've already observed, CampaignMission objects are only used for the board, while the event handles logic for when the mission is ongoing.

1.  How do we detect whether a given Mission is currently active?
An active mission will have an event, so look for that with Global.getSector().getEventManager().isOngoing(null, eventTypeId)
(To check for the presence of a mission on a board, use the sector mission board API: Global.getSector().getMissionBoard())

Quote
2.  How do we inject a Mission into the UI (i.e., offer to annul the Commission) if 1 is true?
missionBoard.makeAvailableAt(missionObject, market)
Do this for every market where the mission will need displaying

Quote
3.  Can we invoke public code in that other Mission to end it?
Code: java
        CampaignEventPlugin eventSuper = sector.getEventManager().getOngoingEvent(null, Events.FACTION_COMMISSION);
        if (eventSuper == null) return;
        sector.getEventManager().endEvent(eventSuper);
But! This has a bug: the commission event does not fully end. It persists in the intel screen list of missions, and its isDone() method returns false, although its callins are no longer called.

Spoiler
[close]

Depending on what you're doing, you could override the vanilla event; change its class in events.json to a child class whose endEvent() method is public. I expect problems if more than one mod decides to do this.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3773 on: January 25, 2018, 09:41:03 AM »

Yeah, that (mod conflicts) was also on my mind with this.

I'm not sure that the problem with the Commission ending is a bug, per se, more like something acting a little wonky:

Code
	private boolean ended = false;
private void endEvent() {
ended = true;

Global.getSector().getCharacterData().getMemoryWithoutUpdate().unset(MemFlags.FCM_FACTION);
Global.getSector().getCharacterData().getMemoryWithoutUpdate().unset(MemFlags.FCM_EVENT);
}

This only gets invoked if:

Code
		RepLevel level = faction.getRelToPlayer().getLevel();
if (!level.isAtWorst(RepLevel.NEUTRAL)) {
endEvent();
Global.getSector().reportEventStage(this, "annul", findMessageSender(),
MessagePriority.ENSURE_DELIVERY,
new BaseOnMessageDeliveryScript() {
public void beforeDelivery(CommMessageAPI message) {

}
});
}

So, if that isn't happening... it won't ever return true.  Not a bug, per se, more of an oversight, because of the "you can take this Commission back later if your Reputation rises again" is probably taking place... whereas what is probably the right answer is to run cleanup()... I'll take a look at this.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3774 on: January 25, 2018, 10:13:30 AM »

Ah, yeah, this is becoming more clear.  I think that cleanup() needs to be invoked in FactionCommissionMission, not FactionCommissionEvent.

So... I need to write a watcher as an EveryFrameScript that will populate the Mission Board with the anti-mission if the player has accepted a Commission; when the anti-mission is "accepted", it should nuke the FactionCommissionMission via cleanup() and let FactionCommissionMissionCreator do its thing. 

Should be clean and easy, and if it works, feel free to port.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3775 on: January 25, 2018, 12:22:47 PM »

Got it. 

I've gotten the bug you encountered dealt with, too; players can renounce their Commission (without losing rep) and take up the Commission again, any time they wish, and it's showing up correctly in the Intel screen.

Thanks much for the help understanding this.

Here's code, feel free to port:

EveryFrameScript for master control; needs to be started up by the ModPlugin.
Code: java
package data.scripts;

import com.fs.starfarer.api.EveryFrameScript;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.FactionAPI;
import com.fs.starfarer.api.campaign.MissionBoardAPI;
import com.fs.starfarer.api.campaign.MissionBoardAPI.MissionAvailabilityAPI;
import com.fs.starfarer.api.campaign.econ.MarketAPI;
import com.fs.starfarer.api.util.IntervalUtil;
import com.fs.starfarer.api.util.Misc;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unchecked")
public class CommissionEndScript implements EveryFrameScript {

private final MissionBoardAPI board;
private final IntervalUtil tracker = new IntervalUtil(0.25f, .75f);

public CommissionEndScript() {
board = Global.getSector().getMissionBoard();
}

    //EveryFrameScripts must implement these
    @Override
    public boolean isDone()
    {
        return false;
    }

    @Override
    public boolean runWhilePaused()
    {
        return false;
    }

    @Override
    public void advance(float amount)
    {
float days = Global.getSector().getClock().convertToDays(amount);
tracker.advance(days);
if (tracker.intervalElapsed() && Misc.getCommissionFactionId() != null) {
// which factions need to have commissions on offer?
List<FactionAPI> factions = new ArrayList<>();
for (FactionAPI faction : Global.getSector().getAllFactions()) {
if(faction.getId().equalsIgnoreCase(Misc.getCommissionFactionId())) factions.add(faction);
}

// sync missions available with list of what needs to be on offer
for (MissionAvailabilityAPI ma : board.getMissionsCopy()) {
if (ma.getMission() instanceof FactionCommissionMissionAnnul) {
FactionCommissionMissionAnnul fcm = (FactionCommissionMissionAnnul) ma.getMission();
if (!factions.contains(fcm.getFaction())) {
board.removeMission(fcm, true);
} else {
fcm.setTimestamp(Global.getSector().getClock().getTimestamp());
factions.remove(fcm.getFaction());
}
}
}
//Just create this mission for the Faction we're allied with.
for (FactionAPI faction : factions) {
createMission(faction);
}
}
    }

protected void createMission(FactionAPI faction) {
FactionCommissionMissionAnnul mission = new FactionCommissionMissionAnnul(faction.getId());
for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
if (market.getFaction() == faction) {
board.makeAvailableAt(mission, market);
}
}
}
}

Core mission script, basically does the real work here:
Code: java
package data.scripts;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.FactionAPI;
import com.fs.starfarer.api.campaign.MissionBoardAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.MissionBoardAPI.MissionAvailabilityAPI;
import com.fs.starfarer.api.campaign.RepLevel;
import com.fs.starfarer.api.campaign.events.CampaignEventManagerAPI;
import com.fs.starfarer.api.campaign.events.CampaignEventPlugin;
import com.fs.starfarer.api.impl.campaign.missions.BaseCampaignMission;
import com.fs.starfarer.api.impl.campaign.missions.FactionCommissionMissionEvent;
import com.fs.starfarer.api.util.Misc;

public class FactionCommissionMissionAnnul extends BaseCampaignMission {
private FactionAPI faction;

public FactionCommissionMissionAnnul(String factionId) {
this.faction = Global.getSector().getFaction(factionId);

CampaignEventManagerAPI eventManager = Global.getSector().getEventManager();
event = eventManager.primeEvent(null, "faction_commission_annul", this);
}

@Override
public void advance(float amount) {
super.advance(amount);
}

public FactionAPI getFaction() {
return faction;
}

@Override
public String getFactionId() {
return faction.getId();
}

@Override
public String getPostingStage() {
return super.getPostingStage();
}

@Override
public String getName() {
return Misc.ucFirst(faction.getDisplayName()) + " Commission Renounce";
}

@Override
public void playerAccept(SectorEntityToken entity) {
super.playerAccept(entity);

//Remove this after accepted.
MissionBoardAPI board = Global.getSector().getMissionBoard();
for (MissionAvailabilityAPI ma : board.getMissionsCopy()) {
if (ma.getMission() instanceof FactionCommissionMissionAnnul) {
FactionCommissionMissionAnnul fcm = (FactionCommissionMissionAnnul) ma.getMission();
board.removeMission(fcm, true);
}
}

//We are doing some silly stuff here; essentially bumping player Reputation down, triggering the end of the Commission, then back up. 
//The key here to resolving that Intel bug is that we're calling Advance() before we call cleanup(), so that the FactionCommissionMissionEvent runs properly.
//Works, though!

FactionAPI commFaction = Misc.getCommissionFaction();
float rep = commFaction.getRelationship("player");
commFaction.setRelationship("player", RepLevel.SUSPICIOUS);
FactionCommissionMissionEvent tEvent = Misc.getCommissionEvent();
if(tEvent != null){
tEvent.advance(1f);
tEvent.cleanup();
}
commFaction.setRelationship("player", rep);
}

@Override
public boolean canPlayerAccept() {
return true;
}

@Override
public CampaignEventPlugin getPrimedEvent() {
return event;
}
}

This is a dummy Mission Event, pretty much just here to support the UI code that expects one.
Code: java
package data.scripts;

import java.awt.Color;
import java.util.List;
import java.util.Map;

import com.fs.starfarer.api.campaign.InteractionDialogAPI;
import com.fs.starfarer.api.campaign.events.CampaignEventTarget;
import com.fs.starfarer.api.campaign.rules.MemoryAPI;
import com.fs.starfarer.api.impl.campaign.events.BaseEventPlugin;
import com.fs.starfarer.api.util.Misc;
import com.fs.starfarer.api.util.Misc.Token;
import java.util.ArrayList;

public class FactionCommissionMissionAnnulEvent extends BaseEventPlugin {
private FactionCommissionMissionAnnul mission = null;

@Override
public void init(String type, CampaignEventTarget eventTarget) {
super.init(type, eventTarget, false);
}

protected Object readResolve() {
return this;
}

@Override
public void setParam(Object param) {
mission = (FactionCommissionMissionAnnul) param;
faction = mission.getFaction();
getEventTarget().getEntity().setFaction(mission.getFaction().getId());
}

@Override
public void startEvent() {
super.startEvent(true);
}

@Override
public void advance(float amount) {
}

@Override
public boolean callEvent(String ruleId, final InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
return true;
}

@Override
public Map<String, String> getTokenReplacements() {
Map<String, String> map = super.getTokenReplacements();
map.put("$sender", faction.getDisplayName());
addFactionNameTokens(map, "other", faction);
return map;
}

@Override
public String[] getHighlights(String stageId) {
List<String> result = new ArrayList<>();
addTokensToList(result, "");
return result.toArray(new String[0]);
}

@Override
public Color[] getHighlightColors(String stageId) {
return super.getHighlightColors(stageId);
}

@Override
public boolean isDone() {
return true;
}

@Override
public String getEventName() {
return Misc.ucFirst(faction.getDisplayName()) + " Commission - annulled";
}

@Override
public CampaignEventCategory getEventCategory() {
return CampaignEventCategory.MISSION;
}

@Override
public String getEventIcon() {
return faction.getCrest();
}
}

In events.json:
Code
	# missions - DO NOT supply the "image" parameter, it's not used anywhere
# implement CampaignEventPlugin.getEventIcon() instead.
"faction_commission_annul":{
"script":"data.scripts.FactionCommissionMissionAnnulEvent",
},

In reports.csv (not sure if both are necessary, but heck, why not):
Code
# faction commission annul,,,,,,,,,,,,
faction_commission_annul,posting,,,posting,"Removes your obligation to this Faction.","You will no longer be allied with this Faction.",,,,important,,
faction_commission_annul,accept,,,secure_comm,posting,"Removes your obligation to this Faction.","You will no longer be allied with this Faction.",,,important,,
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3776 on: January 29, 2018, 06:50:26 AM »

How do I reload rules.csv in devmode? The old "drag file to another folder, undo" thing no longer seems to work in 0.8.1a.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23988
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3777 on: January 29, 2018, 08:42:26 AM »

Hmm - as far as I'm aware, nothing about how that works has changed. Can you try actually making a meaningless edit to the file? It might be your OS decided to treat the move/move back differently somehow...
Logged

bananana

  • Commander
  • ***
  • Posts: 226
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3778 on: January 30, 2018, 01:36:17 AM »

sup, FS!
how can i get shield center coordinates and shield radius of a target ship?
how can i get a point, that is different from weapon.getlocation by known amount. i.e. get weapon barrel end coordinates?
Logged
Any and ALL sprites i ever posted on this forum are FREE to use. even if i'm using them myself. Don't ever, EVER ask for permission, or i will come to your home and EAT YOUR DOG!!!
i do NOT want to see my name appear in the credits section of any published mod and will consider it a personal insult.

NightKev

  • Commander
  • ***
  • Posts: 104
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3779 on: January 30, 2018, 03:43:22 AM »

For shield information, it looks like you can do `ShipAPI.getShield()` which returns a `ShieldAPI` object with information about the ship's shields, which you can then query for more information (cf: this section of the Starfarer API javadoc).
Logged
Pages: 1 ... 250 251 [252] 253 254 ... 706