Author Topic: BC 1.1 - Secondary shield generators  (Read 5138 times)

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC 1.1 - Secondary shield generators
« Reply #40 on: September 19, 2011, 03:43:04 PM »
My current python here is 2.6. Havn't run in any problems so far.

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2187
  • Cookies: 1706
  • Life is life
Re: BC 1.1 - Secondary shield generators
« Reply #41 on: September 19, 2011, 03:45:27 PM »
Mine is 2.4
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #42 on: September 19, 2011, 04:39:38 PM »
Good, I don't need to mess about installing all manner of different Python versions.  :yay:
Great men are not peacemakers! Great men are conquerors!

Offline jayce

  • Posts: 20
  • Cookies: 2
Re: BC 1.1 - Secondary shield generators
« Reply #43 on: September 20, 2011, 12:48:25 AM »
the bc engine doesnt work like that, you actually have to have an enemy target your primary shield generator for the right amount of damage to happen, but the enemy AI usually just target the ship in general.


  • if you're responding to my previous post then yes, bc works exactly like that.
  • the ai can target any damagable ship object property, in any order of importance, including the shield generator property, as long as those properties are flagged as targetable.

i presented the easiest method for Bat66wat6 to try as tweaking a hardpoint by changing a few numbers around is a lot easier than trying to tweak an ai by adding/removing simple lines of script/code.

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #44 on: September 20, 2011, 08:40:29 AM »
I know what it does and the design principals behind what it does. I also have a good design of how my implementation of the script could operate, however this is not enough.

The first step to modifying it is first understanding it. I've been trying to go through the script and comment all the lines to know precisely what is going on, to no avail.

I have no insight into how this script operates. I don't even know what any of the data types are because Python variables are dynamically typed.

Seriously, a question directed straight towards the scripters of BC.

How do you know what functions are available in BC and even know what they do? It's a project in it's self just finding all of them to try and understand what goes on inside them and what they return. Script imports into imports into imports and it all amasses into one big spaghetti mess  :banghead:

Furthermore, there is no way to see what the hell is going on when the damned thing is executed by BC. I try to put in some print statements, in the hopes they will output to the ingame console, but it just falls of a cliff and spits an error when it reaches my output statements!  :help:


Do you just guess how it is going to run? If only this was C or C++ and I could run through it line by line with a compiler :(
Great men are not peacemakers! Great men are conquerors!

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC 1.1 - Secondary shield generators
« Reply #45 on: September 20, 2011, 08:52:21 AM »
Can you post your current file and the error you get?

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #46 on: September 20, 2011, 10:07:08 AM »
The error as dumped by ConsoleTracker into scripts\Custom\ConsoleTrackDump.txt
Code: [Select]
Error: was unable to load ShieldGenerators - SyntaxError: ('invalid syntax', ('.\\Scripts\\Custom\\QBautostart\\ShieldGenerators.py', 60, 4, '\011\011\011\011print ShieldPercentage\012'))
Traceback (innermost last):
  File ".\Scripts\Custom\Autoload\LoadEngineeringExtension.py", line 157, in ImportQBautostart
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 60
     print ShieldPercentage
     ^
 SyntaxError: invalid syntax
####

####
Traceback (innermost last):
  File "c:\utopia\current\build\scripts\Bridge\EngineerCharacterHandlers.py", line 563, in AnnounceShields
ZeroDivisionError: float division
####

The script you gave me as it currently stands is attached to this post; 154 lines pasted into the post body wouldn't look pretty.
Note that aside from some comments I added here and there the only change to the script is the print statement on line 60.
Great men are not peacemakers! Great men are conquerors!

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC 1.1 - Secondary shield generators
« Reply #47 on: September 20, 2011, 10:27:38 AM »
Ok two things:
1. You have to understand the errors BC gives you
In this case a Syntax Error in line 60 which is explained below.

2. Indention plays a major role in Python programming:
The line before your print statement is on 2 Tabs, while the print statement is in the same block is 4 Tabs - it should have 2 as well!

How do you know what functions are available in BC and even know what they do? It's a project in it's self just finding all of them to try and understand what goes on inside them and what they return. Script imports into imports into imports and it all amasses into one big spaghetti mess  :banghead:
I look for how TG has done it. Example: How to play a Video?
I search for the string Opening.bik and it gives me MainMenu/mainmenu.py. I can copy from that.
What functions do? Personally I guess it from their name.

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #48 on: September 20, 2011, 10:57:29 AM »
Thanks for spotting the stupid mistake. It should be a lot easier to play with the script now that I can find out what all the values are!  :)

Sorry, I must look like a complete idiot given I said I'm going through the 2.4 documentation nicely. I fully understand the role of indentation in Python but I decided to use a different text editor in place of the Python interpreter because it offers clearer syntax highlighting. It must have somehow had the indentation setup wrong. I will try to stick with IDLE from now on, indentation errors aren't something I want to bother you with.  :doh:

I'm surprised that even experienced top-dog BC scripters who have alot of experience with Python end up more or less guessing what functions do. It shows how badly you can be screwed over when the functions used are hidden behind layer after layer of imports.
Great men are not peacemakers! Great men are conquerors!

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC 1.1 - Secondary shield generators
« Reply #49 on: September 20, 2011, 11:17:38 AM »
Just set the Editor to 1 Tab = 8 Spaces and you should be fine. Note that other people here might use different settings.

Sov for example is using 8 spaces instead of tabs in his Python scripts.

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #50 on: September 20, 2011, 11:55:43 AM »
Thanks for the tip. I have changed the number of spaces in a tab to 8 and am now using my favorite text editor to work on the script.

The Python IDLE seems so limiting. Basic miscellaneous text editing features are missing, it seems really inflexible when it comes to editing code. One thing that springs to mind is visual displays of code blocks according to their indentation.
Great men are not peacemakers! Great men are conquerors!

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2187
  • Cookies: 1706
  • Life is life
Re: BC 1.1 - Secondary shield generators
« Reply #51 on: September 20, 2011, 01:26:20 PM »
Quote
Sov for example is using 8 spaces instead of tabs in his Python scripts.

I pretty much convert all scripts to this kind of indentation. I prefer spaces over tabs, it usually works better with different kinds of text editors.

Quote
Thanks for the tip. I have changed the number of spaces in a tab to 8 and am now using my favorite text editor to work on the script.

The Python IDLE seems so limiting. Basic miscellaneous text editing features are missing, it seems really inflexible when it comes to editing code. One thing that springs to mind is visual displays of code blocks according to their indentation.

Hehehe a small tip: Python IDE. http://pydev.org/ I think is free, I can't be certain, also it requires Eclipse. I personally use WingIDE, it's not free but I've got a license.
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #52 on: September 20, 2011, 03:58:46 PM »
Thanks for the tip. I might check out the tool but if it isn't free and isn't superior to Notepad++ (my favorite text editor) I won't be using it.
Great men are not peacemakers! Great men are conquerors!

Offline Mario

  • Senior Software Developer
  • Administrator
  • Posts: 2187
  • Cookies: 1706
  • Life is life
Re: BC 1.1 - Secondary shield generators
« Reply #53 on: September 20, 2011, 04:29:49 PM »
NPP does not work well for python if indentation is mixed with tabs + whitespace character.
Acta, non verba.
aka USS Sovereign

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #54 on: September 20, 2011, 04:54:27 PM »
Ok, I will try to be careful for stupid indentation problems when using Notepad++.

Many of the variables have weird values I have never seen before.
Some examples are:
Code: [Select]
pPropSet = <C TGModelPropertySet instance at _6140ea0_p_TGModelPropertySet>
pShipSubSystemPropInstanceList = <C TGModelPropertyList instance at _6110050_p_TGModelPropertyList>
pInstance = <C TGModelPropertyInstance instance at _646bb9c_p_TGModelPropertyInstance>
pProperty = <C ShieldProperty instance at _6468830_p_ShieldProperty>

Why are these crazy values being returned? What do they represent?

The key to my implementation method is differentiating between the Primary and Secondary shield generators. How can I do that if crazy values like this are returned from the TG BC functions?
Great men are not peacemakers! Great men are conquerors!

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC 1.1 - Secondary shield generators
« Reply #55 on: September 21, 2011, 02:52:19 AM »
They are instances of classes
Code: [Select]
pPropSet = pShip.GetPropertySet()
Will give you all Hardpoints of that ship

Code: [Select]
pShipSubSystemPropInstanceList = pPropSet.GetPropertiesByType(App.CT_SHIELD_PROPERTY)
Only Shield Generators in your Hardpoint

Code: [Select]
iNumItems = pShipSubSystemPropInstanceList.TGGetNumItems()
pShipSubSystemPropInstanceList.TGBeginIteration()
Will obviously start the iteration over the shield generators.

Code: [Select]
for i in range(iNumItems):
        pInstance = pShipSubSystemPropInstanceList.TGGetNext()
        pProperty = App.ShieldProperty_Cast(pInstance.GetProperty())
So now we loop over all our shield generators. The current one is in pProperty.
pInstance is exactly the same as in the Hardpoint.

For example we can use SetPrimary() and IsPrimary() which can we use do distinguish the real generator to the fake ones.

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #56 on: September 21, 2011, 04:50:03 AM »
Okay... :lostit:

We can distinguish between the real and the two fake generators using IsPrimary(), however how do we distinguish between the fake Primary and the Secondary shield generators? I need the Primary generator to take precedence over the secondary or this whole exercise is worthless.

Some of the unique attributes that set the two generators apart are:
    • Their names.
    • Individual shield values, Secondary shield has 1/2 strength of the Primary.
    • Shield recharge/reload rate, again 1/2 of the Primary.
    • Their position on the ship.

    The greatest distinction between the two hardpoints is their names, so I would say that's the most obvious way to distinguish between them. However, I haven't seen a function that obtains the subsystem name so I'm unsure if using the name is a unique identifier is possible.
Great men are not peacemakers! Great men are conquerors!

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC 1.1 - Secondary shield generators
« Reply #57 on: September 21, 2011, 05:18:27 AM »
No, you can't replace the Shield Generators. One will have to stay primary all the time.

Thats why I worked around that: You fill the Real Shield Generators will the Values from the fake active Generator.

Offline Bat66wat6

  • Posts: 144
  • Cookies: 34
  • Running custom BC 1.1
Re: BC 1.1 - Secondary shield generators
« Reply #58 on: September 21, 2011, 07:02:17 AM »
No, you can't replace the Shield Generators. One will have to stay primary all the time.

Thats why I worked around that: You fill the Real Shield Generators will the Values from the fake active Generator.
I completely understand.

After reading my last reply I see how you could think I am trying to change the Primary() value when I am not. I know that is impossible.

Instead I want to swap the real shield generators values over with the Primary (targetable) and Secondary (targetable) shield generators as they each become disabled/operational.
I want the values of the Primary (targetable) and Secondary (targetable) to remain seperate.

In pseudocode this would be:
Code: [Select]
IF primary (targetable) generator is disabled:
    IF secondary(targetable) generator is operational:
        # primary (targetable) is offline, secondary shield generator takes over
        real primary generator shield strength = secondary (targetable) shield generator strength
        real primary generator shield reload(charge) = secondary (targetable) shield generator shield reload(charge)
    ELSE:
        # both generators are disabled, there are no shields
        real primary generator shield strength = 0
        real primary generator shield reload = 0

# VICE-VERSA, secondary offline & primary becomes active
IF secondary (targetable) generator is disabled:
    IF primary(targetable) generator is operational:
        # secondary (targetable) is offline, primary is operational and ready to work
        real primary generator shield strength = primary (targetable) shield generator strength
        real primary generator shield reload(charge) = primary (targetable) shield generator shield reload(charge)
    ELSE:
        # both generators are disabled, there are no shields
        real primary generator shield strength = 0
        real primary generator shield reload = 0

You get the idea.

I want to keep the two shield generators completely seperate from each other. Instead of piling all the shields of both targetable shield generators together I want to assign the values of each targetable generator to the real shield generator.

Say targetable primary generator ("Primary Shield Generator") has the following values:
Front:
Aft:44000
Left: 22000
Right:22000
Dorsal:44000
Ventral:44000
Reload: 48

And targetable secondary generator ("Secondary Shield Generator") has the following values:
Front:
Aft:22000
Left: 11000
Right:11000
Dorsal:22000
Ventral:22000
Reload: 24

At any given time the values assigned to the real hidden indestructible generator are either those of "Primary Shield Generator" OR "Secondary Shield Generator" OR 0 all round (nothing, no shields).
NEVER are any values of the two separate targetable generators added together.

And of course I want the ingame shield values to be remembered for when a shield generator becomes operational again.
By this I mean that if for example: You are in battle and someone punches through your top shield (which becomes red), they then disable the targetable "Primary Shield Generator" (which is the active shield generator at the time). The "Secondary Shield Generator" then becomes the active generator.

When the disabled, but not destroyed targetable "Primary Shield Generator" becomes operational again I want the previous shield values of that shield to be restored. This means that whatever damage the shields on the "Primary Shield Generator" incurred when it was active before it was disabled, will be restored.
The generators original HP file (\scripts\ships\hardpoint) values should NOT be restored. The "Primary Shield Generator" should NOT come back online at full strength (all shields green).


Of course, this entire implementation method depends on being able to find out which one of the non-real (non-primary not IsPrimary() ) are the "Primary Shield Generator" and the "Secondary Shield Generator".

IF primary (targetable) generator is disabled:
    xxxxxxxxxxxxxxxxxxxx
IF secondary (targetable) generator is disabled:
    xxxxxxxxxxxxxxxxxxxx
Great men are not peacemakers! Great men are conquerors!

Offline Defiant

  • Posts: 398
  • Cookies: 1105
    • BC: Kobayashi Maru
Re: BC 1.1 - Secondary shield generators
« Reply #59 on: September 21, 2011, 10:26:05 AM »
ok you could set the primary and secondary via the Foundation plugin (scripts/Custom/Ships/)

e.g. for the Scimitar in RemanScimitar.py:
Code: [Select]
Foundation.ShipDef.RemanScimitar.lShields = ["Shield Generator Main", "Shield Generator Aux 1"] # Name from Hardpoint

You could read this value later with
Code: [Select]
sShipType = GetShipType(pShip)
pFoundationShip = Foundation.shipList[sShipType]
lShields = pFoundationShip.lShields

So you can do something like
Code: [Select]
if pProperty.GetName() == lShields[0]:
   # this is the primary, do something
elif pProperty.GetName() == lShields[1]:
   # this is the first auxiliary, do something else

Also you then can do something like
Code: [Select]
pShieldMain = MissionLib.GetSubsystemByName(pShip, lShields[0]) # get Primary
pShieldAux = MissionLib.GetSubsystemByName(pShip, lShields[1]) # get Secondary

if pShieldMain.IsDisabled():
    ...
elif pShieldAux.IsDisabled():
   ...
else:
   ...