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)

Author Topic: Global.getCombatEngine().getFleetManager(ENEMY or PLAYER).spawnFleetMember  (Read 1796 times)

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile

Global.getCombatEngine().getFleetManager(ENEMY or PLAYER).spawnFleetMember

spawns player owned ships, even if the fleetside is ENEMY.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile

Thanks for the report.

What's happening is it's using the owner of the fleet member (which is correct) but there's, as far as I can see, no way to set the owner to anything other than the player, if it happens to be a FleetMemberAPI you've created via FactoryAPI, rather than one you got from another fleet. Added to FleetMemberAPI:
int getOwner();
void setOwner(int owner);
Logged

Uomoz

  • Admiral
  • *****
  • Posts: 2663
  • 'womo'dz
    • View Profile

Thanks alex! I had to resort to this since I want to refit ships on the fly inside a mission and the only method I know works is FMAPI.setVariant(); can I possibly hack my way around using ShipAPI?

EDIT:
Also ShipAPI.getOwner() appears to always return neither player or enemy when used on hulks (is "disabled" an owner?)

Screen with ships spawned with getOwner of hulks on the map (both for player or enemy ships, now hulks).





« Last Edit: May 29, 2014, 03:56:18 AM by Uomoz »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile

(Moving this to modding because it's going in that direction.)

I think you could hack around this by switching the side of the ship on the fly; something like:
Code: java
ship.resetOriginalOwner();
ships.getOwner(1);
if (ship.isFighter()) {
for (Ship fighter : ship.getWing().getMembers()) {
fighter.resetOriginalOwner();
fighter.setOwner(1);
}
if (ship.getWing() != null) {
ship.getWing().setWingOwner(1);
}
}

That should work, but might have some side effects... though since you're actually deploying from the correct fleet manager, maybe it won't. (If you weren't, you'd have to do surgery on the fleet manager's data, and I don't think enough is exposed in the API for that.)

Also ShipAPI.getOwner() appears to always return neither player or enemy when used on hulks (is "disabled" an owner?)

Disabled ships have an owner of 100, which is "neutral". Asteroids etc do too. You can use ship.getOriginalOwner() to get the owner id from before it was destroyed. This is why the above code is calling resetOriginalOwnerId(), btw - so that when you change the owner of the ship, the original owner also changes.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile

We really could use a method to spawnShipOrWing that allows the parameter of NEUTRAL and places them in a different DeployedFleetAPI :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack