Author Topic: Rescale.py (discussion)  (Read 618 times)

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Rescale.py (discussion)
« on: January 05, 2020, 02:52:39 PM »
Yes, this again. I'm sure this topic has been talked about over and over.. but...

I was using this function recently, but realized that it has some funny side effects. For one, the max impulse of the ships are affected, which tells me at least some of the hardpoint is being rescaled; my guess is pShip.GetImpulseEngineSubsystem().GetMaxSpeed() as I was able to multiply by a weird value to restore this to very close to original max impulse velocities, I do believe the angular velocity/accel and maxaccel are also rescaled. The math does not seem to add up. Second, and most obvious, the beams emit from either far off the ship for scaled down models or (I am assuming here), too far into the model on a scaled up ship. I have tried to fix the latter with no luck. I looked in App and MissionLib for clues. I have yet still a few things to try, but I am coming here in hopes some of you have more technical input than I have seen in searches around here. I present you with some code:

Code: [Select]
from bcdebug import debug
################################################################################################################
#
# Tethys notes-
#
# One thing I have noticed about Rescale mod is that it not only rescales the ship model, but also
# rescales some subsystem properties (example: rescale Impulse System max speed value), yet it fails to
# rescale other hardpoint attributes (phaser beam origin point). I have formulated a fix which I believe
# can be applied to other rescaled subsystem properties. The math behind the fix is not right (it seems
# to multiply itself 3-fold), its more or less a best guesstimate. Additionally, some scripting is
# incomplete or incorrect, but I believe with some persistence and clever coding it can be possible to
# also rescale the child subsystems origin points. WIP
#
# I would also like to use a dynamic ShipName (sCurName)? rather than a static one, if I can ever figure
# that out...
#
################################################################################################################
import App
import MissionLib

MODINFO = { "needBridge": 0 }

# use the ShipName of the Hardpoint file as key here
g_dShipScales = {
       "Akira": 0.4,
       # "USSCentury": 0.4,
}

def ObjectCreatedHandler(pObject, pEvent):
        debug(__name__ + ", ObjectCreatedHandler")
        pShip = App.ShipClass_Cast(pEvent.GetDestination())
        if pShip:
rescale(pShip)
pObject.CallNextHandler(pEvent)


def rescale(pShip):
if not pShip:
return
if not pShip.GetShipProperty():
return
sShipProbName = pShip.GetShipProperty().GetShipName()
for sCurName in g_dShipScales.keys():
if sCurName == sShipProbName:
pShip.SetScale(g_dShipScales[sCurName])

# Okay, so we need to scale up some things that got reduced and scale down some things that were missed...
ImpEng = pShip.GetImpulseEngineSubsystem()
MaxSpeed = ImpEng.GetMaxSpeed() #2696 USSCentury 6740
ImpEng.GetProperty().SetMaxSpeed(MaxSpeed*1.35725)

PhaSys = pShip.GetPhaserSystem()
PhaRadius = PhaSys.GetRadius()
PhaSys.GetProperty().SetRadius(PhaRadius/1.35725)

# Something here disappears alot of buttons, probably a hang up due to invalid values/code or incorrectly selected XYZ
# iWeapons = PhaSys.GetChildSubsystems()
# iWeapons = pShip.GetPhaserSystem().GetChildSubsystems()
# position = iWeapons.GetPosition()
# position2d = iWeapons.GetPosition2D()
# iWeapons.GetProperty().SetPosition(position/1.35725)
# iWeapons.GetProperty().SetPosition2D(position2d/1.35725)

# The following is not really intended to work, the structure was broken intentionally (more for info than use)
# if PhaSys:
# iWeapons = PhaSys.GetChildSubsystems()
# for iWeap in range(iWeapons):
# qWeaponChild = PhaSys.GetChildSubsystem(iWeapons)
# if str(qWeaponChild) != str(PhaSys):
# position = iWeapons.GetPosition()
# position2d = iWeapons.GetPosition2D()
# iWeapons.SetPosition(position/1.35725)
# iWeapons.SetPosition2D(position2d/1.35725)
# pSequence = App.TGSequence_Create()
# pSet = pPlayer.GetContainingSet()
# pEmitFrom = App.TGModelUtils_CastNodeToAVObject(pPlayer.GetNode())
# pPlayerNode = pPlayer.GetNode()
# pAttachTo = pSet.GetEffectRoot()
# vEmitPos  = qWeaponChild.GetPosition()"""

def init():
        debug(__name__ + ", init")
        App.g_kEventManager.AddBroadcastPythonFuncHandler(App.ET_OBJECT_CREATED, MissionLib.GetMission(), __name__ + ".ObjectCreatedHandler")
        App.g_kEventManager.AddBroadcastPythonFuncHandler(App.ET_OBJECT_CREATED_NOTIFY, MissionLib.GetMission(), __name__ + ".ObjectCreatedHandler")

# Adjust existing ships
lSets = App.g_kSetManager.GetAllSets()
for pSet in lSets:
for pShip in pSet.GetClassObjectList(App.CT_SHIP):
rescale(pShip)

Offline CMDR CHESS

  • Posts: 34
  • Cookies: 3
  • "With the first link, the chain is forged..."
Re: Rescale.py (discussion)
« Reply #1 on: January 06, 2020, 01:25:44 AM »
What ship are you modifying right now?
Look for a copy of that ship, or save the NIF as something else to restore it later. It's not the Hardpoints that are changing but the scale of the ship itself. One I like to do when some ships have just too big of a part that need over sized radius to make contact.

Offline Tethys

  • -=USF=- Co-Leader
  • Posts: 256
  • Cookies: 89
Re: Rescale.py (discussion)
« Reply #2 on: January 06, 2020, 09:00:48 AM »
What ship are you modifying right now?

I was playing around with the Century Class but I changed to the stock Akira because it is easier to select and everyone here has it

Look for a copy of that ship, or save the NIF as something else to restore it later. It's not the Hardpoints that are changing but the scale of the ship itself. One I like to do when some ships have just too big of a part that need over sized radius to make contact.

Then how do you explain things like the Impulse subsystem max speed being affected by Rescale?

Additionally, I had a look in MissionLib and also App (the 2 imports required by Rescale) and found BaseObjectClass.SetScale however the class set doesnt seem to handle any of the hardpoints, yet empirically I see it affecting hardpoints within the game. Surely ship MaxSpeed doesnt just change itself based on model size, does it? Because if it does, I cannot find where in App or MissionLib... so its possible that is hard coded in the exe (I have a hex editor, I can have a brief look...)

Offset: 53A760 (there is a TGPoint SetScale label)
Offset: 578270 (some interesting clues may be here)

I still think it is possible to change the hardpoint with scripting. I have affected the hardpoint with scripting, and so has JB2005 with the Install Cloak mod. Perhaps I will also have a look at replacing the entire weapon property in a similar fashion. But that would involve grabbing the parent subsystem and all children within, something I have not yet success with.

Digging further it appears that changing the subsystem child placement location has no effect on from where the beam originates.