Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 239 240 [241] 242 243 ... 711

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

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3600 on: September 23, 2017, 09:25:23 AM »

Are you compiling a JAR?  Most likely, you're hitting a Janino issue there.

But mainly, you're doing that in a totally-inefficient way, from the look of that.

The isWithinRange() is redundant; if it's in the area variable, it's already in range, if the logic's written correctly.  So, for example, if you're trying to do something semi-randomized to one ship in that area (like heal them):

Code
boolean hasHealed = false;
int tooManyRepeats = 0;
//Get this list only one time, ever; expensive square-root invocation in getting distances between Vector2fs!
List<ShipAPI> targets = AIUtils.getNearbyAllies(beamtarget, area);
while(!has Healed && tooManyRepeats < 1000){
for(ShipAPI target :  AIUtils.getNearbyAllies(beamtarget, area)){
//Keep adding to this each pass so that we're limited to 1000 invocations of getRandomInRange()
//This means the while operation can fail but can't lock up the game-sim (usually the right answer for real-time code)
tooManyRepeats += 1;
//Only does this logic 1 in 100 passes
if(MathUtils.getRandomInRange(1f,100f) > 99f){
--> do healing logic here
//Use this as a break to leave the while loop
hasHealed = true;
}
}
}

Lastly, the right way to get a number from 0 --> end of a List's size:

myList.get(MathUtils.getRandomNumberInRange(0,myList.size()-1));

MathUtils.getRandomNumberInRange() is capable of getting numbers in float and integer values automatically.
« Last Edit: September 23, 2017, 09:27:53 AM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Morrokain

  • Admiral
  • *****
  • Posts: 2143
  • Megalith Dreadnought - Archean Order
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3601 on: September 26, 2017, 12:12:25 AM »

Is PersonAPI.setPortraitSprite(String portraitName) bugged?

Doesn't seem to work. I put in portrait_hegemony01 (no quotes) into rules, call that into a string as a parameter of the script, then pass that into that method.

In the campaign, I get a blank portrait screen and a null pointer exception like it can't find the portrait.

The PersonAPI definition of that particular method would also work as I can't seem to find it in the API, just references to it.
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4693
    • View Profile
    • GitHub profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3602 on: September 26, 2017, 02:26:34 AM »

You need to specify the full sub-path, e.g. graphics/portraits/portrait_hegemony01.png

(This won't affect your specific example, but it also needs to be loaded somewhere by specifiying it in the faction file or in settings.json)
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3603 on: September 26, 2017, 03:34:42 AM »

Are you compiling a JAR?  Most likely, you're hitting a Janino issue there.

But mainly, you're doing that in a totally-inefficient way, from the look of that.

/snip


In case anyone copies that code example, it needs mentioning that its performance is broken. (See target assignment expression)
It could also be done with less, more efficient code, but that's a secondary issue.
« Last Edit: September 26, 2017, 03:36:35 AM by TJJ »
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 #3604 on: September 26, 2017, 09:46:15 PM »

You need to specify the full sub-path, e.g. graphics/portraits/portrait_hegemony01.png

(This won't affect your specific example, but it also needs to be loaded somewhere by specifiying it in the faction file or in settings.json)

Ah, thanks! Works as intended now.  :D
Logged

bananana

  • Commander
  • ***
  • Posts: 229
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3605 on: September 28, 2017, 01:39:50 AM »

so i mutilated ion beam script.
now this thing fires emp arcs at everything in range around point of impact, dealing set amount of damage, evenly distributed.
affects friendlies as well - not intentional, but will make weapon harder to use. also more fair, because lightning doesn't care about IFF.

the whole script:
Spoiler
Quote
package data.scripts;

import org.lwjgl.util.vector.Vector2f;

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.CombatEntityAPI;
import com.fs.starfarer.api.combat.DamageType;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.impl.campaign.ids.Stats;
import com.fs.starfarer.api.util.IntervalUtil;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.lazylib.combat.entities.SimpleEntity;
import org.lwjgl.util.vector.Vector2f;
import org.lazywizard.lazylib.combat.CombatUtils;
import java.util.List;

public class TF_BEAM_ARC implements BeamEffectPlugin {

   float delay = 0.75f;
   
   @Override
   private IntervalUtil fireInterval = new IntervalUtil(delay, delay*3f);
   private boolean wasZero = true;
   
   public void advance(float amount, CombatEngineAPI engine, BeamAPI beam) {
      CombatEntityAPI beamtarget = beam.getDamageTarget();
      if (beamtarget instanceof CombatEntityAPI && beam.getBrightness() >= 1f) {
         float dur = beam.getDamage().getDpsDuration();
         // needed because when the ship is in fast-time, dpsDuration will not be reset every frame as it should be
         if (!wasZero) dur = 0;
         wasZero = beam.getDamage().getDpsDuration() <= 0;
         fireInterval.advance(dur);
         
         if (fireInterval.intervalElapsed()) {   
         
               Vector2f dir = Vector2f.sub(beam.getTo(), beam.getFrom(), new Vector2f());
               if (dir.lengthSquared() > 0) dir.normalise();
               dir.scale(50f);
               Vector2f point = Vector2f.sub(beam.getTo(), dir, new Vector2f());
               
               float emp = beam.getWeapon().getDamage().getFluxComponent() * delay; //emp
               float dam = beam.getWeapon().getDamage().getDamage() * delay;      //damage
               float area =600f;
               float empmainwidth = 40;
                       
                  for(CombatEntityAPI target :  CombatUtils.getEntitiesWithinRange(point, area)){
                  
            int num   = CombatUtils.getEntitiesWithinRange(point, area).size();   //get number of enemies      
                        
            Vector2f arcsplit = new Vector2f(MathUtils.getRandomPointOnLine(point,beam.getWeapon().getLocation()));   
                  //secondary emp arc. decorative
                  engine.spawnEmpArc(
                              beam.getSource(),
                              beam.getWeapon().getLocation(),
                              beam.getSource(),
                              new SimpleEntity(arcsplit),
                              DamageType.ENERGY,
                              0, // damage
                              0, // emp
                              100000f, // max range
                              "tachyon_lance_emp_impact",
                              empmainwidth,
                              beam.getFringeColor(),
                              beam.getCoreColor()
                              );    
                  //main emp arc
                  engine.spawnEmpArc(
                              beam.getSource(),
                              arcsplit,
                              beam.getSource(),
                              target,
                              DamageType.ENERGY,
                              dam/num, // damage
                              emp/num, // emp
                              100000f, // max range
                              "tachyon_lance_emp_impact",
                              empmainwidth/num,
                              beam.getFringeColor(),
                              beam.getCoreColor()
                              );
                     }   
         }
      }
   }   
}
[close]
i'm kinda ok with how it works, but would like some expert opinion if i did something horribly wrong

also

how can i insert a delay between arcs.
without using ShipAPI target = <ShipAPI>targets.get(...); which doesn't seem to work :P
« Last Edit: September 28, 2017, 10:25:59 PM 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.

King Alfonzo

  • Admiral
  • *****
  • Posts: 683
  • -- D O C T O R --
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3606 on: September 30, 2017, 12:08:22 AM »

The BRIEFEST of questions:

In weapon files, there is the line:

Code
	"renderHints":[RENDER_BARREL_BELOW],

This tells the game to render the barrel below the base sprite, easy. The question I have is: is there a RENDER_BAREEL_ABOVE or something similar? Tried render above, but it didn't seem to be recognised by the ship editor.  I'm making a sort of real-life midrange shotgun weapon, where instead of the barrel bouncing back, a sort of pump action casing outside the barrel jumps back instead.

bananana

  • Commander
  • ***
  • Posts: 229
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3607 on: September 30, 2017, 01:58:25 AM »

This tells the game to render the barrel below the base sprite, easy. The question I have is: is there a RENDER_BAREEL_ABOVE or something similar?
just leave the field blank. it'll do the trick.

also a question
is it possible to render "base" sprite below "under" sprite? :P

also a question
how can i make projectile use random debris sprite? so it's different for each projectile from the same weapon.

« Last Edit: September 30, 2017, 04:39:06 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.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3608 on: September 30, 2017, 09:46:26 AM »

is it possible to render "base" sprite below "under" sprite? :P

It's not.

how can i make projectile use random debris sprite? so it's different for each projectile from the same weapon.

Barring some creative hackery I'm unaware of, also no - sorry :)


how can i insert a delay between arcs.

I'm not sure I understand the question. I mean, there's the "interval" stuff in the script already to do that, so I guess the answer would be "use that instead of doing it twice in a row"? But I'm guessing you've looked at that already so I'm probably missing some aspect of the question.

Edit: another option would be to add a script to the combat engine that'll add an emp arc after a delay and then have its isDone() method return true.
Logged

MesoTroniK

  • Admiral
  • *****
  • Posts: 1731
  • I am going to destroy your ships
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3609 on: September 30, 2017, 05:37:10 PM »

how can i make projectile use random debris sprite? so it's different for each projectile from the same weapon.

Barring some creative hackery I'm unaware of, also no - sorry :)

Well, two ways to go about it really.

An everyframe plugin that removes and replaces the shot choosing from a list of different projectiles. This is unfortunately rather expensive and thus unsuitable for a rapid fire weapon. Alex, why is projectile spawning via script so dang expensive? If it wasn't I would totally make things like this (cheated extremely high rate of fire, with properly staggered bullet streams)...



Or the projectile uses a blank sprite, and an everyframe plugin renders the shot visual through direct sprite rendering fun, choosing from a list of different sprites. This if done correctly, is fine performance wise.

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3610 on: September 30, 2017, 06:18:29 PM »

Quote
how can i make projectile use random debris sprite? so it's different for each projectile from the same weapon.
That's actually really easy to do with the FX Mod.

You'd make an invisible projectile for your weapon, then spawn an FX particle using the random SpriteAPI you want going the same velocity, etc., then tie that to the weapon (presumably, using a HashMap, where the projectile, if it's done any damage, then triggers the FX particle's lifetime to fade away).
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3611 on: September 30, 2017, 07:16:09 PM »

Alex, why is projectile spawning via script so dang expensive?

If you're passing in a null ship parameter, it has to create a fake one, so that probably takes a bit. If not, it should actually be pretty fast, as far as I can tell.
Logged

MesoTroniK

  • Admiral
  • *****
  • Posts: 1731
  • I am going to destroy your ships
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3612 on: September 30, 2017, 08:09:25 PM »

Alex, why is projectile spawning via script so dang expensive?

If you're passing in a null ship parameter, it has to create a fake one, so that probably takes a bit. If not, it should actually be pretty fast, as far as I can tell.

Stuff from the past which experimented with creating weapons with ludicrous rates of fire via shot spawning (but not more than say several Vulcans firing at the same time) bogged down the performance even on rigs with high-end CPUs. And both those experiments, and modern things in the Modiverse which do not use shot spawning on weapons with high rates of fire always link the ship. So, on less powerful rigs, even not trying to mimic that gif with the Phalanx systems, is going to tank performance so I avoid using shot spawning for anything that fires faster than what might be considered "semi-automatic" as the overall rule of thumb.
« Last Edit: September 30, 2017, 08:12:33 PM by MesoTroniK »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24157
    • View Profile
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3613 on: October 03, 2017, 07:41:13 AM »

Just gave it a try; spawning a lightmg projectile 10 times per frame dropped the idle time from 94% to around 88% on my rig (with only an Apogee deployed). That's about, what, 30 Vulcans firing at the same time, so that much of a drop seems about right. Looking at a profiler, nothing unexpected there, just looks like the extra time is spent rendering/doing collision checking/etc.

Spawning 100 shots per frame drops the idle to single digits, but again, the vast majority of that load is due to having that many projectiles in flight rather than the cost of spawning new ones.

The code was this, btw, in an EveryFrameCombatPlugin:

Code: java
ShipAPI playerShip = engine.getPlayerShip();
if (playerShip != null && !playerShip.isShuttlePod()) {
WeaponAPI w = ((WeaponAPI)((WeaponGroupAPI) playerShip.getWeaponGroupsCopy().get(0)).getWeaponsCopy().get(0));
for (int i = 0; i < 10; i++) {
engine.spawnProjectile(playerShip, w, "lightmg", playerShip.getLocation(),
playerShip.getFacing() + (float) Math.random() * 360f, playerShip.getVelocity());
}
}

Passing in null for a weapon did not change things appreciably.
Logged

Dark.Revenant

  • Admiral
  • *****
  • Posts: 2806
    • View Profile
    • Sc2Mafia
Re: Misc modding questions that are too minor to warrant their own thread
« Reply #3614 on: October 03, 2017, 10:50:19 AM »

The weapon MesoTroniK refers to is one that fires a lot of projectiles that last a long time and fly a long range, so that might just be expected results.
Logged
Pages: 1 ... 239 240 [241] 242 243 ... 711