Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.98a is out! (03/27/25)

Pages: 1 ... 12 13 [14] 15 16 ... 45

Author Topic: API request thread (please read OP before posting!)  (Read 274106 times)

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: API request
« Reply #195 on: May 24, 2014, 01:55:45 AM »

ArmourAPI.getGridCoordinates() returns List<Vector2f>

or

class AmourCell{
getArmourFraction()
getCoordinate()

private
float fraction
Vector2f coordinates
}
etc. as an interface


return List<ArmourCell>
« Last Edit: May 24, 2014, 02:13:48 AM by Debido »
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1819
    • View Profile
Re: API request
« Reply #196 on: May 24, 2014, 12:01:18 PM »

I've been using this to get the absolute location of an armor cell:
Spoiler
Code: java
    public static Vector2f getCellLocation(ShipAPI ship, float x, float y) {
        x -= ship.getArmorGrid().getGrid().length / 2f;
        y -= ship.getArmorGrid().getGrid()[0].length / 2f;
        float cellSize = ship.getArmorGrid().getCellSize();
        Vector2f cellLoc = new Vector2f();
        float theta = (float)(((ship.getFacing() - 90) / 360f) * (Math.PI * 2));
        cellLoc.x = (float)(x * Math.cos(theta) - y * Math.sin(theta)) * cellSize + ship.getLocation().x;
        cellLoc.y = (float)(x * Math.sin(theta) + y * Math.cos(theta)) * cellSize + ship.getLocation().y;

        return cellLoc;
    }
[close]
Not exactly clean or efficient, but it works. I'm sure matrix transformation would be better. It would be nice if the API provided this functionality though.
« Last Edit: May 24, 2014, 12:10:54 PM by Sundog »
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1906
    • View Profile
Re: API request
« Reply #197 on: May 24, 2014, 12:07:51 PM »

I've been using this to get the absolute location of an armor cell:
Spoiler
Code: java
    public static Vector2f getCellLocation(ShipAPI ship, float x, float y) {
        x -= ship.getArmorGrid().getGrid().length / 2f;
        y -= ship.getArmorGrid().getGrid()[0].length / 2f;
        float cellSize = ship.getArmorGrid().getCellSize();
        Vector2f cellLoc = new Vector2f();
        float theta = (float)(((ship.getFacing() - 90) / 350f) * (Math.PI * 2));
        cellLoc.x = (float)(x * Math.cos(theta) - y * Math.sin(theta)) * cellSize + ship.getLocation().x;
        cellLoc.y = (float)(x * Math.sin(theta) + y * Math.cos(theta)) * cellSize + ship.getLocation().y;

        return cellLoc;
    }
[close]
Not exactly clean or efficient, but it works. I'm sure matrix transformation would be better. It would be nice if the API provided this functionality though.

350 seems like an odd number to use for converting degrees into radians?
Logged

Sundog

  • Admiral
  • *****
  • Posts: 1819
    • View Profile
Re: API request
« Reply #198 on: May 24, 2014, 12:10:32 PM »

Dear god! How did that happen...
Good catch TJJ. Edited my post to remove that... embarrassment.
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: API request
« Reply #199 on: May 24, 2014, 12:35:26 PM »

I've been using this to get the absolute location of an armor cell:
Spoiler
Code: java
    public static Vector2f getCellLocation(ShipAPI ship, float x, float y) {
        x -= ship.getArmorGrid().getGrid().length / 2f;
        y -= ship.getArmorGrid().getGrid()[0].length / 2f;
        float cellSize = ship.getArmorGrid().getCellSize();
        Vector2f cellLoc = new Vector2f();
        float theta = (float)(((ship.getFacing() - 90) / 360f) * (Math.PI * 2));
        cellLoc.x = (float)(x * Math.cos(theta) - y * Math.sin(theta)) * cellSize + ship.getLocation().x;
        cellLoc.y = (float)(x * Math.sin(theta) + y * Math.cos(theta)) * cellSize + ship.getLocation().y;

        return cellLoc;
    }
[close]
Not exactly clean or efficient, but it works. I'm sure matrix transformation would be better. It would be nice if the API provided this functionality though.

Nice! This makes life easier. So I pass each cell from the getGrid(), I should be able to give myself a list of all the armour cell Vector2f point locations?

EDIT: Hm, ok. Nope...can't do that with it.
« Last Edit: May 24, 2014, 01:54:57 PM by Debido »
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1906
    • View Profile
Re: API request
« Reply #200 on: May 24, 2014, 02:52:24 PM »

Dear god! How did that happen...
Good catch TJJ. Edited my post to remove that... embarrassment.

Np.
Classic example of why you should use the API methods where available :)
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: API request
« Reply #201 on: May 24, 2014, 03:27:49 PM »

CombatFleetManagerAPI.holdTheLine() prevents the enemy AI from calling a retreat. They fight to the death and the very last ship...including ships the are generated from spawnShipOrWing.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: API request
« Reply #202 on: May 24, 2014, 08:21:53 PM »

A couple of requests:

DamagingProjectileAPI / .proj boolean doNotCreateParticles - No missile explosion graphics get generated via Vanilla code, including the automagic death explosions when missiles are killed (which are quite expensive, btw, but I cannot determine why without seeing the function- I'd really like to be able to replace them entirely).

CombatEntityAPI setPosition() - I'm not quite sure what's up, but it appears that using Vector2f setX() / setY() on the Vector2f generated by getLocation() isn't always as reliable as I'd like. 

I tried writing code strictly limiting the flight of ships that aren't using TravelDrive to the game arena, but it's not working terribly well when ships are being spawned (if they leave TravelDrive outside the arena, they're ending up in the corners) and when they attempt to leave via Retreat, even though they have TravelDrive on, they're still having issues.  Nothing I can't live with but I'd like to be able to fix it properly and I have a feeling that attempting to set the positions is getting ignored / overridden.
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25935
    • View Profile
Re: API request
« Reply #203 on: May 24, 2014, 09:16:59 PM »

CombatEntityAPI setPosition() - I'm not quite sure what's up, but it appears that using Vector2f setX() / setY() on the Vector2f generated by getLocation() isn't always as reliable as I'd like. 

I tried writing code strictly limiting the flight of ships that aren't using TravelDrive to the game arena, but it's not working terribly well when ships are being spawned (if they leave TravelDrive outside the arena, they're ending up in the corners) and when they attempt to leave via Retreat, even though they have TravelDrive on, they're still having issues.  Nothing I can't live with but I'd like to be able to fix it properly and I have a feeling that attempting to set the positions is getting ignored / overridden.

(Pretty sure something else is going on there, getLocation().x = <whatever> should work. That's what the core game uses for things like the teleporter.)
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: API request
« Reply #204 on: May 24, 2014, 09:59:35 PM »

Yeah, it's some weird issues with top / bottom of the battlefield related to handling of Retreat, I think.  IDK quite what's causing stuff to suddenly teleport to corners, though.  I'll look at this again :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Sundog

  • Admiral
  • *****
  • Posts: 1819
    • View Profile
Re: API request
« Reply #205 on: May 25, 2014, 12:06:16 AM »

Classic example of why you should use the API methods where available :)
Forsooth  :)

So I pass each cell from the getGrid(), I should be able to give myself a list of all the armour cell Vector2f point locations?

EDIT: Hm, ok. Nope...can't do that with it.
I should have mentioned; the float x/float y parameters of the function are meant to be the index coordinates (in the 2d array returned by getGrid()) of the cell you want the location of. I can't remember why I used floats rather than ints. Anyway, if I understand what you need correctly, it should be something like this:
Spoiler
Disclaimer - Untested

Code: java
    public static List getCellLocations(ShipAPI ship) {
        int width = ship.getArmorGrid().getGrid().length;
        int height = ship.getArmorGrid().getGrid()[0].length;
        //List cellLocations = new ArrayList(width * height);
        // Not sure if above works the way I think it does.
        List cellLocations = new ArrayList();
       
        for(int x = 0; x < width; ++x) {
            for(int y = 0; y < height; ++y) {
                cellLocations.add(getCellLocation(ship, x, y));
            }           
        }
       
        return cellLocations;
    }
[close]
Logged

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: API request
« Reply #206 on: May 25, 2014, 12:58:10 PM »

MissionDefinitionAPI

api.addEveryFrameCombatPlugin(org.blah.missions.plugins, myMissionScript);

When the mission loads, it will call the init and advance sections of this script - but ONLY during the mission. The script is otherwise inactive and does nothing.

This allows us to have a custom mission script that is only active for the duration of the mission. After the mission ends you no longer call the script.

For instance, lets say you wanted to have a mission where you spawned in enemies in waves, or is event driven, condition driven etc. but you don't want to have to do elaborate checks within the EveryFrameCombatPlugin to ensure that it is never otherwise activated under any other circumstances.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: API request
« Reply #207 on: May 25, 2014, 01:02:36 PM »

You can already do all that by defining a custom missile AI :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Debido

  • Admiral
  • *****
  • Posts: 1183
    • View Profile
Re: API request
« Reply #208 on: May 25, 2014, 01:21:50 PM »

You can already do all that by defining a custom missile AI :)

Was that about the mission specific EveryFrameCombatPlugin?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 25935
    • View Profile
Re: API request
« Reply #209 on: May 25, 2014, 01:34:59 PM »

MissionDefinitionAPI

api.addEveryFrameCombatPlugin(org.blah.missions.plugins, myMissionScript);

I'm confused. There's already:
MissionDefinitionAPI.addPlugin(EveryFrameCombatPlugin plugin);
Am I missing something here?


On a general note: this thread is turning a bit into "questions about how to do stuff", in part, because some of the stuff being asked for is already possible. This is going to make it much more time-consuming to go through later and figure out what actually needs to be added. If you're not sure whether something can already be done or not, please ask about it in the Modding section first.

It's also not about requesting new features (the Suggestions forum is there for that), but rather about exposing functionality - via the API - that's already in the game. There's some gray area there, of course, but still. If feature suggestions were to go in this thread, it'd be completely unmanageable, and it's going into that territory. A good rule of thumb is that if the core game doesn't already do what you're asking for or something very close to it, then it doesn't belong here.


CombatFleetManagerAPI.holdTheLine() prevents the enemy AI from calling a retreat. They fight to the death and the very last ship...including ships the are generated from spawnShipOrWing.

For example - absolutely not to single you out personally - this kind of thing definitely belongs in Suggestions and not here.


I'd like to keep this thread clean and focused. Thanks! :)
Logged
Pages: 1 ... 12 13 [14] 15 16 ... 45