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 2 3 [4] 5 6 ... 46

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

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1374
    • View Profile
    • GitHub Profile
Re: API request
« Reply #45 on: December 26, 2012, 03:55:27 AM »

SectorEntityToken:
  • LocationAPI getContainingLocation()

FactoryAPI:
  • CargoAPI createCargo()

That would allow us to create temporary/hidden cargo containers without creating fleets or faraway stations. :)

Can weapons exist without a ship? If so, could FactoryAPI get a createWeapon() so we can analyse the properties of weapon stacks (things like weapon size, etc)?

Also, could CargoAPI, CargoStackAPI, and FleetDataAPI get hashCode() implementations based on their contents? It would help when checking if they have been modified (right now we need to keep a copy of their prior contents around to diff against).

On a related note, I expect to have to break some parts of the API horribly after the 0.54.1a release...

Is there any part of the API in particular we should avoid relying on, or can you not tell us without revealing the next planned feature?
« Last Edit: December 26, 2012, 05:31:54 AM by LazyWizard »
Logged
Active mods: LazyLib | Combat Radar | Console Commands | Version Checker  ||  Old mods: Autosave | Omnifactory | Simulator Overhaul
Feel free to use any code I've written or PM me for help with your own. Anyone is free to translate my work.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 26090
    • View Profile
Re: API request
« Reply #46 on: December 26, 2012, 10:17:52 AM »

SectorEntityToken:
  • LocationAPI getContainingLocation()

Added. Let me see about the other ones... might not get to them for this release, though.

Also, could CargoAPI, CargoStackAPI, and FleetDataAPI get hashCode() implementations based on their contents? It would help when checking if they have been modified (right now we need to keep a copy of their prior contents around to diff against).

o1.hashCode() == o2.hashCode() does not imply o1.equals(o2). Am I missing something about how you intended to use it?

On a related note, I expect to have to break some parts of the API horribly after the 0.54.1a release...

Is there any part of the API in particular we should avoid relying on, or can you not tell us without revealing the next planned feature?

'fraid not :) Well, I can "narrow it down" to campaign stuff.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1374
    • View Profile
    • GitHub Profile
Re: API request
« Reply #47 on: December 26, 2012, 10:31:34 AM »

Also, could CargoAPI, CargoStackAPI, and FleetDataAPI get hashCode() implementations based on their contents? It would help when checking if they have been modified (right now we need to keep a copy of their prior contents around to diff against).

o1.hashCode() == o2.hashCode() does not imply o1.equals(o2). Am I missing something about how you intended to use it?

A hash should change if the contents change, correct? So instead of iterating through every stack and comparing them against a reference copy to see if they have changed, we could just use
Code
if (cargo.hashCode() != lastHash)
{
   lastHash = cargo.hashCode();
   // Do stuff
}
Logged
Active mods: LazyLib | Combat Radar | Console Commands | Version Checker  ||  Old mods: Autosave | Omnifactory | Simulator Overhaul
Feel free to use any code I've written or PM me for help with your own. Anyone is free to translate my work.

Wyvern

  • Admiral
  • *****
  • Posts: 4100
    • View Profile
Re: API request
« Reply #48 on: December 26, 2012, 10:35:39 AM »

Not quite; the contract for hashcode is that, if object1.equals(object2), then object1.hashcode() == object2.hashcode().

So, a perfectly valid (if ridiculously suboptimal) hashcode implementation might be something like { return 1; }

Now, the code you suggested should usually work (assuming a mostly-sane hashcode implementation & a .equals method based on contents), but it's not guaranteed.

It sounds like what you want is a .equals method implemented based on contents (which would necessitate a hashcode based on same), and perhaps also a copy constructor.
« Last Edit: December 26, 2012, 10:38:30 AM by Wyvern »
Logged
Wyvern is 100% correct about the math.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 26090
    • View Profile
Re: API request
« Reply #49 on: December 26, 2012, 10:49:54 AM »

(hashCode() javadoc, for reference...)
Logged

Zhentar

  • Commander
  • ***
  • Posts: 100
    • View Profile
Re: API request
« Reply #50 on: December 29, 2012, 05:26:53 PM »

It sounds like what you want is a .equals method implemented based on contents (which would necessitate a hashcode based on same), and perhaps also a copy constructor.

What he wants is to be able to tell if the contents have been mutated with a single comparison. The easiest way to accomplish this is not by implementing equals/hashCode (I dunno about Java, but in .NET land making either of those depend on mutable state is considered a bad idea), but instead by exposing a "version" counter that gets incremented whenever the contents are modified.
Logged

Wyvern

  • Admiral
  • *****
  • Posts: 4100
    • View Profile
Re: API request
« Reply #51 on: January 01, 2013, 08:18:55 AM »

Could we get a getHullType method?  At the moment, we're limited to something like:
Code
	 private static String getHullType( FleetMemberAPI ship ) {
if (ship.isFighterWing()) {
return ship.getSpecId();
}
int lastIndex = ship.getSpecId().lastIndexOf("_");

if (lastIndex > 0) {
return ship.getSpecId().substring(0, lastIndex);
}

return ship.getSpecId();
}
Which works fine most of the time, but fails if, for example, someone made a default variant with a name like "liao-freighter-standard" instead of "liao-freighter_standard".
Logged
Wyvern is 100% correct about the math.

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1374
    • View Profile
    • GitHub Profile
Re: API request
« Reply #52 on: January 01, 2013, 08:30:10 AM »

I'm wondering, does FleetMemberAPI have an underlying ShipAPI object for bonus calculation and display? If so, could FleetMemberAPI have a getShip() method?
Logged
Active mods: LazyLib | Combat Radar | Console Commands | Version Checker  ||  Old mods: Autosave | Omnifactory | Simulator Overhaul
Feel free to use any code I've written or PM me for help with your own. Anyone is free to translate my work.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 26090
    • View Profile
Re: API request
« Reply #53 on: January 01, 2013, 12:39:39 PM »

Could we get a getHullType method?  At the moment, we're limited to something like:
Code
	 private static String getHullType( FleetMemberAPI ship ) {
if (ship.isFighterWing()) {
return ship.getSpecId();
}
int lastIndex = ship.getSpecId().lastIndexOf("_");

if (lastIndex > 0) {
return ship.getSpecId().substring(0, lastIndex);
}

return ship.getSpecId();
}
Which works fine most of the time, but fails if, for example, someone made a default variant with a name like "liao-freighter-standard" instead of "liao-freighter_standard".

Added FleetMemberAPI.getHullId(). Returns the hull (*not* wing) id for fighters, btw.

I'm wondering, does FleetMemberAPI have an underlying ShipAPI object for bonus calculation and display? If so, could FleetMemberAPI have a getShip() method?

It doesn't. (new Ship objects get created all over the place - for the tooltip, for the duration of a battle, every time anything about the loadout changes on the refit screen, etc), but it does have a MutableShipStats object stats for what you've said. Added MutableShipStatsAPI getStats(); to FleetMemberAPI.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1374
    • View Profile
    • GitHub Profile
Re: API request
« Reply #54 on: January 02, 2013, 08:15:40 AM »

I'm wondering, does FleetMemberAPI have an underlying ShipAPI object for bonus calculation and display? If so, could FleetMemberAPI have a getShip() method?

It doesn't. (new Ship objects get created all over the place - for the tooltip, for the duration of a battle, every time anything about the loadout changes on the refit screen, etc), but it does have a MutableShipStats object stats for what you've said. Added MutableShipStatsAPI getStats(); to FleetMemberAPI.

Just to check: we could then use getStats().getEntity() to get at the currently generated ShipAPI, or would it return null in this case?

Also, DamagingProjectileAPI and BeamAPI both have a getDamageTarget(), but BeamAPI's returns a ShipAPI and DamagingProjectileAPI returns an Object. Shouldn't both of these return a CombatEntityAPI?
« Last Edit: January 02, 2013, 08:17:46 AM by LazyWizard »
Logged
Active mods: LazyLib | Combat Radar | Console Commands | Version Checker  ||  Old mods: Autosave | Omnifactory | Simulator Overhaul
Feel free to use any code I've written or PM me for help with your own. Anyone is free to translate my work.

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1374
    • View Profile
    • GitHub Profile
Re: API request
« Reply #55 on: January 02, 2013, 09:31:05 AM »

CargoStackAPI:
  • CargoAPI getContainer()
Logged
Active mods: LazyLib | Combat Radar | Console Commands | Version Checker  ||  Old mods: Autosave | Omnifactory | Simulator Overhaul
Feel free to use any code I've written or PM me for help with your own. Anyone is free to translate my work.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 26090
    • View Profile
Re: API request
« Reply #56 on: January 02, 2013, 11:22:08 AM »

Added.

Re: getEntity() - right, that'll return null.

getDamageTarget() - both return a CombatEntityAPI now.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1374
    • View Profile
    • GitHub Profile
Re: API request
« Reply #57 on: January 04, 2013, 10:56:08 AM »

ShipAPI:
  • List getDrones()
  • ShipAPI getDroneSource()

I think we are missing something like the above two methods for dealing with drones.

Sprog's suggestion thread makes me think a get/setOutlivesSource(boolean) would be useful for drones as well.
Logged
Active mods: LazyLib | Combat Radar | Console Commands | Version Checker  ||  Old mods: Autosave | Omnifactory | Simulator Overhaul
Feel free to use any code I've written or PM me for help with your own. Anyone is free to translate my work.

Wyvern

  • Admiral
  • *****
  • Posts: 4100
    • View Profile
Re: API request
« Reply #58 on: January 04, 2013, 11:03:12 AM »

Another useful parameter would be something like setNoCorpse(boolean) - important for when you have drones that launch drones.
Say we've got ship A launches drones D1 which launch drones D2.  Recalling D1 pulls them back in - but doesn't make the D1 drones recall their D2 drones, resulting in dead D2 drones, typically hovering right over ship A and causing massive damage, similar to what happens when you spawn with a collection of asteroids inside your ship.

If we could set the D2 drones to leave no corpse, this would be a non-issue; as it is, recalling the D1 drones is almost always a really bad idea.
Logged
Wyvern is 100% correct about the math.

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1374
    • View Profile
    • GitHub Profile
Re: API request
« Reply #59 on: January 04, 2013, 11:08:48 AM »

A getIndex() for drones would also be useful if we want to code special effects for certain drones in a formation.
Logged
Active mods: LazyLib | Combat Radar | Console Commands | Version Checker  ||  Old mods: Autosave | Omnifactory | Simulator Overhaul
Feel free to use any code I've written or PM me for help with your own. Anyone is free to translate my work.
Pages: 1 2 3 [4] 5 6 ... 46