Bridge Commander Central

BC Forums => BC Scripting => Topic started by: Bat66wat6 on September 14, 2011, 06:14:53 AM

Title: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 14, 2011, 06:14:53 AM
I was unsure as to where I should put this topic, BC Modding or BC Scripting, however since seemingly everything in the game is dictated by a Python script in one way or another I decided on the BC Scripting area.

The Scimitar is capable of being a great ship in Bridge Commander however there are a few technical problems. Leaving out 'fire through cloak' the big problem I am stuck on now is how to make the Secondary Shield Generator actually do something.
-----------------------------------------
How feasible is the notion of a functioning Secondary shield generator on a ship in Bridge Commander version 1.1?

Would it be possible to put down some Python code that toggles the "primary" switch of the shield generator hardpoints so that when the primary shield generator is damage to 75% (disabled) it's "primary" hardpoint value is toggle to 0 while the secondary shield generator "primary" value is toggled to 1. Then, when and if the primary shield generator is repaired to say 80% the opposite happens and the primary values of both hardpoints are switched.

Because I know very little about Python scripting I don't know how feasible it is to pull this off, which is obviously why I am asking here. However, there are so many other seemingly far more complex things that the BC modding community has created such as Galaxy charts, Kobayashi Maru, warp core ejection, warp engine plasma leaks etc etc etc.

Thanks for taking the time to read I look forward to your replies.
Title: Re: BC 1.1 - Secondary shield generators
Post by: KrrKs on September 14, 2011, 08:29:24 AM
I'm not sure if toggling the "primary" setting is really necessary. I remember on of the DS9 Stations (not sure which one) had three Shield Generators.
When one of those was disabled, the Overall Shield- Strength simply dropped by that Generators Value. (I.E. Overall Shield Strengh was 15K, after one Generator disabled, Shield Strength dropped to 10K, assuming every Generator ads 5K.)
Maybe you have to experiment with the "Primary" setting.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 14, 2011, 09:22:57 AM
I had not thought of it in that way. When it was announced in the movie that there was a secondary shield generator I thought it implied the generator as a backup. Something that would only be active when the primary generator was knocked offline.

My severely limited knowledge of Python scripting and what goes on behind everything I see in the game only restricts me to turning the Primary of the hardpoints on and off, however this has no real ingame effect. Two primary generators can't exist at the same time, one cancels each other out so ingame there is still one useless generator.

Having both generators on at once is something i'd rather not do as then it would be a backup generator, it'd just all be one big generator but with two hardpoints to attack.
Title: Re: BC 1.1 - Secondary shield generators
Post by: King Class Scout on September 14, 2011, 10:34:33 AM
this question was asked concerning the Star Empire when I released it through SFRD (as the novel has the ship have Trinary shields). I believe the general consensus was that it couldn't be pulled off in the BC engine due to the engine's sheer age.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 14, 2011, 10:53:24 AM
I have this knack for pursuing things that aren't possible in games  :banghead:
Are you absolutely sure? Is there no validity in KrrKs statement?

I'm not sure if toggling the "primary" setting is really necessary. I remember on of the DS9 Stations (not sure which one) had three Shield Generators.
When one of those was disabled, the Overall Shield- Strength simply dropped by that Generators Value. (I.E. Overall Shield Strengh was 15K, after one Generator disabled, Shield Strength dropped to 10K, assuming every Generator ads 5K.)
Maybe you have to experiment with the "Primary" setting.

How is it that you can create so many complex features and additions such as Kobayashi Maru, with fire through cloak, warp core ejections and all that crazy complex stuff (Galaxy Charts springs to mind) but can't have two shield generators?

 :cry:
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bones on September 14, 2011, 11:02:44 AM
As far as I know, secondary shield generator will do nothing in BC, it will be just another shield gen property that won't be used in game althou you can still see it on the targets list and shoot it.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 14, 2011, 11:26:36 AM
Precisely. It's useless ingame unless there is some functionality behind it. Some kind of magical piece of Python code that looks at the Primary Genny and goes "okay it's broken and not working, let's turn on the second shield generator".

 :help: Cross my fingers a Python wizard walks through the door and says it's not another impossible idea of mine :help:
Title: Re: BC 1.1 - Secondary shield generators
Post by: King Class Scout on September 14, 2011, 12:48:50 PM
Quote
Cross my fingers a Python wizard walks through the door and says it's not another impossible idea of mine
i swear I heard somewhere that Python's a bit...obsolete as a programming language?
who knows. if Soverign or defiant (the KM guy) walks in...

quote from the responses on the SE's comments
Quote
unfortunately, the way BC handles hardpoints, the secondary shield generator won't kick in until the first generator is disabled, by the time that happens, it's probably too late to save the ship.

---Aces High
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 14, 2011, 01:00:04 PM
That last quote in your post doesn't bother me, that's exactly what I want to accomplish. Disable to Primary shield generator in battle and then the secondary shield generator kicks in until the Primary is repaired to a given %

From a Python noobs perspective, such as a feature seems very simple compared to other BC fan made creations that exist. :cry:
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 14, 2011, 02:11:42 PM
Should be possible with something like this and possibly some clever scripting
Code: [Select]
# some code logic which checks the state of primary shield then in an if statement
pPrimaryShield.SetPrimary(0)
pSecondaryShield.SetPrimary(1)
# some more code

However it really depends how will BC recognize and accept the changes or we need to reinit the hp and transfer damage values back to the reinitialized HP. I can't say what would happend as I've never tried it.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 14, 2011, 02:50:22 PM
I am by all accounts a scripting noob however I think I see the difficulties you are touching on. If I am correct the HP file is can't be changed once the game has loaded it to create the ship so simply toggling the primary values on/off is something BC might not like?

Other things created such as the Breen drain weapon can disable all of a ships systems so.... There has to be some way this can be done. One shield on and one shield off. Seems extremely easy compared to other BC fan made creations, but yet again I don't know what the snake will and won't let you do.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 14, 2011, 03:27:55 PM
Quote
Seems extremely easy compared to other BC fan made creations, but yet again I don't know what the snake will and won't let you do.

So did one of our early mods called Emergency System Repair and in the end it turned out to be a 1700 line monster.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 14, 2011, 03:38:30 PM
I am just at the beginning of the programming trails and already know that it's easy to say something and another to do it in code but DAMN, 1700 lines!  :idk:

I hope what I am suggesting, if possible at all, doesn't even come close to that line count!
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 15, 2011, 09:23:50 AM
The script KrrKs is talking of was by me and is - of course - part of KM ;)

http://kobmaru.de/svn/trunk/scripts/Custom/QBautostart/ShieldGenerators.py

It should be easily adaptable for your wishes.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 15, 2011, 03:22:47 PM
Thank you for the script Defiant, much appreciated however...

I feel like such a hopeless noob. I look over the code and have no concrete idea of how it is supposed to work as it is let alone how I could adapt it to switch between primary and secondary shield generators pile both into one super strong shield.

The syntax is alien to me, the functions...I have no idea what some of them do. I go looking for them in App, Foundation and MissionLib only to find more and more imports in those scripts... >  :(

I have ran through the script over and over, some of the functions I understand but most of it... :idk: :banghead:

GetAllShieldGenerators(pShip)
  You set up some form of array (list) comprised of all the shield subsystems and their properties that don't are not Primary(1)

SetUpShip(pShip)
  Not sure why you do what I think you are doing here.
  "Make our 'real' shield generator undestroyable" ? Why, don't see how that even... ?
  I also have no idea why you are setting the disabled ( SetDisabledPercentage(0.0) ) and repair complexity ( SetRepairComplexity(0.0) ) values, aren't they already set in the /scripts/ships/hardpoints/*.py file ?

RedefineShieldGenerators(pShip, ShieldGenerators)
  I know only that in this function you are piling all of the non-disabled shield values into one super shield

Init
  I only know it stands for Initialization and gets the script in motion but beyond that ... ?

All other functions
  Are some form of Python event handler that gets the details of the sub-system, check if it's a shield generator on the players ship and check the count of shield generators on the players ship then call RedefineShieldGenerators if there is > 1. gennies

I say all of this because I want you to understand that I didn't simply download the script, glance at it and run straight here to cry about how it doesn't "do what I want". One of the worst things I think any programmer could endure is to try and help someone who doesn't understand the language.

I also want you to know that I don't like being spoon fed but I am also strongly against the notion of having to learn an entire language just to get a few features into one computer game.

I completely understand if you don't want to practically spoon-feed me everything or do all the work for me and post the script black-box style.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 15, 2011, 03:50:23 PM
Note that you need at least 3 Generators:

1x Not Targetable and Primary:
This is the real shield generator BC will use. It can not be destroyed.
BC can only handle 1 Generator. So we need to work around it by changing its values.

2x Not Primary but Targetable.
These are the generators you will be able to shoot at. They provide the shield strength and reload rate, nothing else.

And this is how it works. The important part is in the function RedefineShieldGenerators().

First in line 48 we get how much generators we have in the variable NumTotalGenerators.

Next (Line 53) we do our calculation for every shield (left, right, aft, ...) and start with 0 for all values.
Code: [Select]
       for Shield in range(App.ShieldClass.NUM_SHIELDS):
                ShieldMax = 0
                ShieldReload = 0
                NumDisabledGenerators = 0
                ShieldPercentage = pShields.GetSingleShieldPercentage(Shield)

So in line for every shield we iterate over every Generator. If the generator is disabled we ignore it. If not we add the strength and reload to the total count.
Code: [Select]

                # for every shield generator
                for Generator in ShieldGenerators:
                        # don't use the disabled generators
                        if Generator.IsDisabled():
                                NumDisabledGenerators = NumDisabledGenerators + 1
                                continue
                        
                        # sum their values
                        ShieldMax = ShieldMax + Generator.GetMaxShields(Shield)
                        ShieldReload = ShieldReload + Generator.GetProperty().GetShieldChargePerSecond(Shield)

Finally the last lines (73) sets the new recharge rate and strength:
Code: [Select]
               pShields.GetProperty().SetMaxShields(Shield, ShieldMax)
                pShields.GetProperty().SetShieldChargePerSecond(Shield, ShieldReload)
                PercentageShieldGeneratorsWorking = 1 - NumDisabledGenerators / float(NumTotalGenerators)
                pShields.SetCurShields(Shield, ShieldMax * PercentageShieldGeneratorsWorking * ShieldPercentage)
So the new shield strength is the sum of all values from all working generators in the hp.

So all you have to do is changing the calculation in lines 73-76.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 15, 2011, 04:01:08 PM
...oh and

So did one of our early mods called Emergency System Repair and in the end it turned out to be a 1700 line monster.

Kobayashi Maru only exists because I wanted to play against AI ships in MP.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 15, 2011, 04:08:54 PM
Damn, I was editing my post and you read the original pre-edit then posted before I could finish.  :picardfacepalm:

Thank you for trying to explain how the script works and what it does. I have a better understanding now however a vague understanding of what it does and how it does it won't give a magical boost that takes me to changing the whole script round to switch between disabled and active generators (primary on - secondary off), (primary off, secondary on).

I genuinely hate my position. I don't want to be a leach.
Title: Re: BC 1.1 - Secondary shield generators
Post by: King Class Scout on September 15, 2011, 07:37:43 PM
gotta remember to keep this script in mind, as I'm retexturing the existing Star Empire, and might use this.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 16, 2011, 08:29:25 AM
Easily adaptable to you maybe.

For me on the other hand changing the way your current script works to the way I want isn't easy.

In my implementation I want the two targetable generators to operate seperately only when the other is knocked out, meaning only one generator at a time. Say for example someone breaks through the top shield and disabled the primary generator. The primary would then go offline, the shields would drop (obviously) then the secondary would kick in and all of the shields would appear to be at full strength again (the secondary shield is half as tough as the primary though).

If the primary is repaired (no longer disabled) I want the secondary to drop and the primary (with all of the shield strength values it had when it went offline, for example the top shield is still red).

I've said what I want in English now putting it into Python code is all I have to do.... :coffee:

EDIT:
Just some noob questions. I am unsure as to the context and scope of how the scripts in QBautostart are executed.

Does the ShieldGenerators.py script in the QBautostart folder apply to all ships?
By this I mean it it executed for every ship that is loaded in QB? Say a battle with 10 ships means it is executed 10 times?

I want this script, for now, only to apply to the Scimitar since it is the only ship in my version of BC that has two shield generators. It would be pointless to have it execute and try to work on every other ship as well.

Additionally, I am assuming that the script is continuously executed in order to work (keep swapping values round when shields are disabled/enabled) right?

Thanks
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 16, 2011, 09:21:04 AM
Enabled for all ships with more then one shield generator.
Title: Re: BC 1.1 - Secondary shield generators
Post by: KrrKs on September 16, 2011, 09:25:50 AM
I think there is a build in Function in App that returns true if a specified System is disabled.

Quote
Does the ShieldGenerators.py script in the QBautostart folder apply to all ships?
- Yes.
However, you can find out a Ships Script Name with (I guess it is a MissionLib Function):  
Quote
pShip.GetScript()
So you can Check all Ships in a Set and only use your Script if the ScriptName is right.

Quote
Additionally, I am assuming that the script is continuously executed in order to work
In Essence yes. It is fired by certain Eventhandlers.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 16, 2011, 02:37:37 PM
Okay thanks, I now have a better understanding of how BC executes QBautostart scripts.

I have been going over the Python documentation & tutorials, if I can find the right functions I think there is a serious chance of being able to pull this script off and achieve the in-game result I want.

It's a matter of being able to differentiate between Primary and Secondary shield generators, as
well as being able to store their shield values when they go offline. I am confident there is a way.

Additionally I want to let you know that your current script has a glitch in it. When the game is running in Test Mode and you use CTRL+SHIFT+R to instantly repair the ship the shields do not come back. However the script works fine when the AI repairs the shield normally so it isn't that bad...
Title: Re: BC 1.1 - Secondary shield generators
Post by: ACES_HIGH on September 16, 2011, 09:30:11 PM
one major hurtle that you might face is that the BC AI doesn't usually attack the shield generator directly, so chances are, the shields will be knocked out well before the generator suffers enough damage to trigger the script to swap to the auxiliary shield generator.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 17, 2011, 06:36:01 AM
True.

I haven't even thought how the AI targets sub-systems. The AI in this game seems very simplistic because they just tend to exclusively target weapons above all else.

However right now I am not particularly concerned how the AI goes about attacking me, my priority is to get the Primary-Secondary shield generator script to work how I want it.
Title: Re: BC 1.1 - Secondary shield generators
Post by: flarespire on September 17, 2011, 01:46:16 PM
maybe you could add a new algorythm to the QB enemy AI which makes them target a ship and something on that ship at random? that may make this secondary shield thing usefull....
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 17, 2011, 02:04:32 PM
That would make he AI Target things like Shuttle Bays or warp engines.
Title: Re: BC 1.1 - Secondary shield generators
Post by: flarespire on September 17, 2011, 02:19:25 PM
exactally...so that would make this secondary shield idea a bit more usefull than just implimenting it.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 17, 2011, 06:19:53 PM
I am running through Python 2.4 documentation.
Regardless of how useful my implementation of the primary secondary shield problem seems I intend to pursue it through to the end.

The AI problem isn't my first priority. Besides, I am under the impression that AI (even apparently simplistic) is not easy to create nor is it easy to change.
Title: Re: BC 1.1 - Secondary shield generators
Post by: jayce on September 17, 2011, 08:24:58 PM
for testing purposes, you could forget about the ai. on your shield generator test ship, just temporarily change the hardpoint of the shield generators. for example, increase the radius of the generator property so that its length/width/height are all larger than the ship itself. also make sure that the generator property is easily disableable. this way, when testing in-game, the generator property would be the first thing to get damaged. this would be a lot easier for you to do than trying to adjust the ai unless
Title: Re: BC 1.1 - Secondary shield generators
Post by: flarespire on September 18, 2011, 06:55:34 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 18, 2011, 04:21:46 PM
The BC AI does Target subsystems. It even has a complex rating algorithm (Preprocessors.py).
Title: Re: BC 1.1 - Secondary shield generators
Post by: flarespire on September 18, 2011, 06:00:00 PM
hmm...maybe we could make it rate the primary shield higher?
Title: Re: BC 1.1 - Secondary shield generators
Post by: JimmyB76 on September 18, 2011, 07:14:17 PM
not really...
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 19, 2011, 05:47:17 AM
So...the AI was just as complex and hard to understand as I initially thought, huh? :nono:

On another note I'm progressing through the documentation nicely and am surprised by the Python language. When I first heard about it I considered it little more than a scripting language. I am surprised by its extensibility, I can see why the developers at Totally Games chose it.

Just one thing. Why the hell are Lambda forms in the language? Functions that are syntactically restricted to one expression, I don't see how they could be of any use.  :lostit: It confuses me that part of another language is incorporated into this one...

Other than that so far it's all good stuff in Python 2.4 Documentation.  :)
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 19, 2011, 08:34:23 AM
On another note I'm progressing through the documentation nicely and am surprised by the Python language. When I first heard about it I considered it little more than a scripting language. I am surprised by its extensibility, I can see why the developers at Totally Games chose it.
A lot of people use it. Google for example. Its a good language for rapid prototyping.

Just one thing. Why the hell are Lambda forms in the language? Functions that are syntactically restricted to one expression, I don't see how they could be of any use.  :lostit: It confuses me that part of another language is incorporated into this one...

Other than that so far it's all good stuff in Python 2.4 Documentation.  :)
Why not? Just note that BC is Python 1.5. It can't do all the stuff of 2.x
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 19, 2011, 11:31:41 AM
It even has a dotnet implementation on top of DLR called IronPython. Not to mention that it's really popular scripting interface. BC is not the only game to use python as a scripting language, Civ 4 also used it. I know a few companies which use IronPython to develop business applications, main program performs operations on the data while ironPython scripts contains the BL.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 19, 2011, 02:02:01 PM
Just note that BC is Python 1.5. It can't do all the stuff of 2.x

Are you sure of this? I based my decision when downloading Python on the sticky thread "Becoming A Scripter 101"

Quote from: USS Sovereign
Python, which can be downloaded from python.org. I strongly recommend downloading no higher than v2.5.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 19, 2011, 02:16:38 PM
Yes, I'm sure. (http://docs.python.org/whatsnew/2.0.html)

Still newer Version is usually better (Bugs fixed, better compatibility with new Windows versions etc). Especially if you want to use Python for other stuff, outside BC.

Sov: Why not higher then 2.5? (Or does it refer to 3.0?)
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 19, 2011, 03:19:51 PM
Goal was to obtain the version closest to 1.5. Obviously 1.x and some 2.x have certain problems running on Vista\7 so I recommended a version up to 2.5. In all honesty 2.5\2.6 have a lot of deprecated modules. So you kind of see my dilemma. For BC you don't go for the latest you go for the closest you can get to BC's version. Not to mention that you can have multiple python versions installed.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 19, 2011, 03:43:04 PM
My current python here is 2.6. Havn't run in any problems so far.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 19, 2011, 03:45:27 PM
Mine is 2.4
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 19, 2011, 04:39:38 PM
Good, I don't need to mess about installing all manner of different Python versions.  :yay:
Title: Re: BC 1.1 - Secondary shield generators
Post by: jayce 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.



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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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 :(
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 20, 2011, 08:52:21 AM
Can you post your current file and the error you get?
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant 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 (http://diveintopython.org/getting_to_know_python/indenting_code.html) 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 20, 2011, 04:29:49 PM
NPP does not work well for python if indentation is mixed with tabs + whitespace character.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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?
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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:
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant 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.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 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
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant 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:
   ...
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 21, 2011, 11:35:58 AM
Your suggestion is brilliant.

I have got Foundation 2008 installed with all of the cool and interesting Ftech stuff such as phase cloak etc. I have even had a little fun by adding the phase cloak to the scimitar.

Despite this it never occured to me that, in a different script in a different directory, you could define the name of the shield generators in a list then access that list from a different script in a different directory.

The fact that this method needs Foundation is completely null and void because at the end of the day ShieldGenerators.py needs QBautostart and obviously QBautostart needs foundation - so nothing is lost  :)


I will go to the script and try to implement this method. I aim to have some results by the end of the day but
more than likely I will post back tomorrow.

 :angel Foundation :angel

EDIT:
I have discovered a bug in the ORIGINAL ShieldGenerators.py script. If I repeatedly disable the targetable Secondary or Primary shield generator the ingame strength of every shield eventually and permanently drops to null. By permanent I mean permanent, once the shield strength drops to nothing the shields never repair to full strength, even if both Primary and Secondary generators repair to 100% hit points.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 22, 2011, 10:24:01 AM
EDIT: I don't normally double post but I doubt that the forum activity update for the thread is triggered when a user edits an existing post.

Naturally I am not very confident in the code I am putting down, given it's my first real experience with Python in the BC environment. However I was not expecting the errors that flew up:

Code: [Select]
####
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 140, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 52, in RedefineShieldGenerators
    sShipType = GetShipType(pShip)
NameError: GetShipType
####
####
Traceback (innermost last):
  File "c:\utopia\current\build\scripts\Bridge\EngineerCharacterHandlers.py", line 563, in AnnounceShields
ZeroDivisionError: float division
####
####
Traceback (innermost last):
  File "c:\utopia\current\build\scripts\Bridge\EngineerCharacterHandlers.py", line 680, in AnnounceSpecificShield
ZeroDivisionError: float division
####
####
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 140, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 52, in RedefineShieldGenerators
    sShipType = GetShipType(pShip)
NameError: GetShipType
####

The GetShipType error is the one I least expected. I have been unable to find the function in App.py, Foundation.py or MissionLib.py
I know a function is needed which returns the type (class) of ship the player is using so it is possible to access the specific Foundation plugin for that ship.

Second the zero division error is obvious given it only occurs when a float with a value of 0.0 is used in a division. I have set all the shield values of the real hidden primary generator to 0 but that error still shouldn't be occuring because of the failsafe code:

Code: [Select]
# some scripts in BC will report zero devision error if the value in shieldmax is 0, so work around
                if ShieldMax == 0.0:
                        ShieldMax = 0.1

Ideas as to why there is still a zero division error?

My version of your script is attached if you want to have a look at how I noobishly have messed up your work.
As always, thanks for your time  :) I know you've always got other things on your plate.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 22, 2011, 12:24:57 PM
Try importing LibQBautostart:
Code: [Select]
from Libs.LibQBautostart import *

Can I also see your current Hardpoint?
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 22, 2011, 12:31:41 PM
About the ship type this is the method you're missing... if not included in QBautostart

Code: [Select]
def GetShipType(pShip):
    if pShip.GetScript():
        return string.split(pShip.GetScript(), '.')[-1]
    return None
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 22, 2011, 05:34:29 PM
Thanks Sovereign and Defiant, I will include the code.  :bow:

And here is one scimitar hardpoint file. I presume the HP file is for the zero-division error.

EDIT:
I added the function given by USS Sovereign, now I get this.

Code: [Select]
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 144, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 56, in RedefineShieldGenerators
    sShipType = GetShipType(pShip)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 14, in GetShipType
    return aString.split(pShip.GetScript(), '.')[-1]
NameError: aString
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 144, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 56, in RedefineShieldGenerators
    sShipType = GetShipType(pShip)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 14, in GetShipType
    return aString.split(pShip.GetScript(), '.')[-1]
NameError: aString

I thought at first it was the variable name being the same as a data type (like that should matter) but obviously that didn't change a thing.
Script attached if you want to have a look.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 23, 2011, 02:03:25 AM
1. Read http://docs.python.org/tutorial/modules.html also you wrote aString instead of string.
But I still prefer importing a library instead of defining this function again.

2. Your Primary Shield Generator has MaxShield of 0. Use at least 1.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 23, 2011, 05:59:26 AM
I changed the name of the variable not because I was bored or wanted to convince myself that I wasn't just blindly pasting whatever code you posted. I did it because I got an error with the original variable name you gave. I thought maybe it was to do with it being named string, which is the name of a data type.  :lostit:

So put this in your pipe and smoke it.  :P
Code: [Select]
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 152, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 57, in RedefineShieldGenerators
    sShipType = GetShipType(pShip)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 14, in GetShipType
    return string.split(pShip.GetScript(), '.')[-1]
NameError: string

And...
Try importing LibQBautostart:
Code: [Select]
from Libs.LibQBautostart import *

I pasted that code in under the other import statements and it spat this at me.
Code: [Select]
Traceback (innermost last):
  File ".\Scripts\Custom\Autoload\LoadEngineeringExtension.py", line 157, in ImportQBautostart
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 4, in ?
ImportError: [b]No module named LibQBautostart[/b]
I performed a full windows search of the BC directory for "LibQBautostart" with 0 results. I also manually looked in both \scripts\Lib and \scripts\custom\qbautostart\Libs

I'm running out of time on this. Damn you BC, damn you! I want my shield generators. I will stop at nothing to get my shield generators! :banghead:
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 23, 2011, 06:06:41 AM
For the "NameError: string": Read my link about importing modules.

LibQBautostart import: Remove it, seems it was never shipped outside of KM :(
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 23, 2011, 08:05:04 AM
What the...  :lostit:

I have defined the function in ShieldGenerators above where I am calling the function. The interpreter knows the functions exists because it meets it before the call. It is in scope. What else could their be?

A NameError? My suspicion falls on this GetScript(). I don't even fully understand the statement being made in GetShipType().
You receive all the details about the players ship in argument pShip: GetShipType(pShip)
Then there is some form of a check to see if it's worth splitting the string: if pShip.GetScript():

return string.split(pShip.GetScript(), '.')[-1]

You create a string variable and assign it the return value of split().
This is where I get lost though because that function/method has two arguments. (delimeter, numOfLinesToCreate)
Quote
Code: [Select]
str.split(str="", num=string.count(str)).

Why is the second argument, which should be an integer, a full stop?
return string.split(pShip.GetScript(), '.')[-1]

Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on September 23, 2011, 08:19:37 AM
Just look at the error, it tells you exactly what is missing. (It starts with s)
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 23, 2011, 09:55:52 AM
I read a small, short introducers PDF tutorial posted on this forum. A few paragraphs in the author warns people that moddifying this game will sap your soul until "your such a geek that your wearing glasses thicker than triple glazing" :funny

Please don't mistake my whining for lack of enthusiasm.

?? NameError ??

 :angel Please enlighten me.  :angel
What coding crime have I commited against Python? Why does it deny me my Primary/Secondary shield generators?
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 23, 2011, 02:10:09 PM
Quote from: Defiant
1. Read http://docs.python.org/tutorial/modules.html also you wrote aString instead of string.
But I still prefer importing a library instead of defining this function again.

QBautostart outside KM does not have this function included (GetShipType) IIRC.


Quote from: Bat66wat6
Code: [Select]
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 152, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 57, in RedefineShieldGenerators
    sShipType = GetShipType(pShip)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 14, in GetShipType
    return string.split(pShip.GetScript(), '.')[-1]
NameError: string

Defiant is right the error is quite clearly explained to you. The method is clearly referencing another module called string. Add this global declaration.
Code: [Select]
import string


Quote from: Bat66wat6
Code: [Select]
Traceback (innermost last):
  File ".\Scripts\Custom\Autoload\LoadEngineeringExtension.py", line 157, in ImportQBautostart
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 4, in ?
ImportError: [b]No module named LibQBautostart[/b]

You probably don't have that module, older QBautostarts used the following module: LibEngineering.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 23, 2011, 07:09:46 PM
Now it's an AttributeError

Code: [Select]
pPrimaryGen = <C ShipSubsystem instance at _6adc93c_p_ShipSubsystem>
pSecondaryGen = <C ShipSubsystem instance at _6ee5c48_p_ShipSubsystem>
activeShieldGen =  <C ShipSubsystem instance at _6adc93c_p_ShipSubsystem>
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 156, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 91, in RedefineShieldGenerators
    ShieldMax = activeShieldGen.GetMaxShields(Shield)
AttributeError: GetMaxShields
pPrimaryGen = <C ShipSubsystem instance at _6f37f68_p_ShipSubsystem>
pSecondaryGen = <C ShipSubsystem instance at _6f380c4_p_ShipSubsystem>
activeShieldGen =  <C ShipSubsystem instance at _6f37f68_p_ShipSubsystem>
Traceback (innermost last):
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 156, in NewShip
    RedefineShieldGenerators(pShip, ShieldGenerators)
  File ".\Scripts\Custom\QBautostart\ShieldGenerators.py", line 91, in RedefineShieldGenerators
    ShieldMax = activeShieldGen.GetMaxShields(Shield)
AttributeError: GetMaxShields

This snake is proving hard to charm.
I threw in some print statements and have found that activeShieldGen does have a value. The variables have the values i expected:

pPrimaryGen = <C ShipSubsystem instance at _6f37f68_p_ShipSubsystem>   :thumbsup:
pSecondaryGen = <C ShipSubsystem instance at _6f380c4_p_ShipSubsystem>   :thumbsup:
activeShieldGen =  <C ShipSubsystem instance at _6f37f68_p_ShipSubsystem>   :thumbsup:

This noob is being pulled out of one hole, taking a step then falling straight into another. :doh:
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 23, 2011, 08:11:13 PM
I shall try to simplify with a very non related example but it will be probably something you'll understand.

c# example, c# as you know is a strong type language.

Code: [Select]
object o = 1;
int i = (int)o + 1;

Code: [Select]
v = MissionLib.GetSubsystemByName(MissionLib.GetPlayer(), "Shield Generator")
if v:
v = App.ShieldClass_Cast(v)
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 24, 2011, 05:45:50 AM
I would love to reply and say I completely understand, however that would be a lie. :(

I have not coded in C# but have done some stuff in C and C++, so there is some similarity.

In the first code example you are showing me assignments that utilize the conversion function int() to ensure that non-integers aren't assigned to an integer data type.

The second example is the reason for lack of complete understanding. You get the class instance of property "Shield Generator" then use an IF to check if the instance exists. What you do inside the IF statement I am unsure. App.ShieldClass_Cast(v)

Just clutching at straws here but I also guess that my problem lies in the area of "trying to assign data to the wrong data type"
OR
Perhaps I am attempting to use a method (function) on the wrong data type? In the original (working) script before I messed things up the GetMaxShields() method was used on the variable Generator in the second for loop of RedefineShieldGenerators(), in my broken version I am trying to use the same method on variable activeShieldGen.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 24, 2011, 11:12:59 AM
Problem of the day is type casting, maybe this will be more familiar to you:
Code: [Select]
System::Object ^o = 1;
int i = safe_cast<int>(o) + 1;

C# samples
Code: [Select]
    public class BaseClass
    {
        protected int x = 0;
        protected int y = 0;

        public BaseClass(int valX, int valY)
        {
            x = valX;
            y = valY;
        }

        public int Subtract()
        {
            return x - y;
        }
    }

public class InheritedClass : BaseClass
    {
        public InheritedClass(int valX, int valY) : base(valX, valY)
        {

        }

        public int Add()
        {
            return x + y;
        }
    }

    static void Main(string[] args)
    {
// init inherited class as object
object o = new InheritedClass(2, 2);
// casting this as a base class I can't see the add method
((BaseClass)o).Subtract();
// cast it correctly then I can see the add method
((InheritedClass)o).Add();
    }

C++ example (CLR)
Code: [Select]
public ref class BaseClass
{
protected:
int x;
int y;

public:
BaseClass(int valX, int valY)
{
x = valX;
y = valY;
}

int Subtract()
{
return x - y;
}
};

public ref class InheritedClass : BaseClass
{
public:
InheritedClass(int valX, int valY) : BaseClass(valX, valY)
{

}

int Add()
{
return x + y;
}
};

int main(array<System::String ^> ^args)
{
// init inherited class as object
System::Object ^o = gcnew InheritedClass(2, 2);
// casting this as a base class I can't see the add method
(safe_cast<BaseClass^>(o))->Subtract();
// cast it correctly then I can see the add method
(safe_cast<InheritedClass^>(o))->Add();
        return 0;
}

Python example. This is a really bad example since the two examples above cannot be translated to python.
Code: [Select]
# lame example I know
class BaseClass:
    def __init__(self, valX, valY):
            self.x = valX
            self.y = valY
    def Subtract(self):
            return self.x - self.y

class InheritedClass(BaseClass):
    def __init__(self, base):
        BaseClass.__init__(self, base.x, base.y)
    def Add(self):
            return self.x + self.y

base = BaseClass(3, 2)
print base.Subtract()
# print base.Add() # this throws out an error
inherited = InheritedClass(base)
print inherited.Add()

I tried to show you is that you can't preform certain operations on datatypes without proper casting.

Now back to the issue at hand. If you actually studied the return types of MissionLib.GetSubsystemByName you would notice that it returns a Subsystem type and that method GetMaxShields is valid for Shield types.

I actually already gave you an answer and posted it in my python example, I'm not sure how you could have missed it. You cast it to shield type and it should work.

Code: [Select]
App.ShieldClass_Cast(activeShieldGen)
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 24, 2011, 02:43:31 PM
Sweeping aside the fact that I said I was going through Python documentation and hadn't even heard of "type casting".

Straight onto the script as is. After implementing the change you spelled out the script now functions almost exactly as I wanted.  :bow:  :thumbsup:  :angel

The only remaining problem is that as I suspected when I first started on the script, the values of the each shield aren't being remembered. The default full strength shield values are being applied everytime a shield generator comes online. This is very wrong :nono:

Say for example, I pummel the primary shields and knock the "Primary Shield Generator" offline, the "Secondary Shield Generator" kicks in. Then when the Primary is repaired it comes on at full strength with all shields green again  :(


I am working on a way to store all the shield values of each shield generator in two lists.
pPrimaryGenShieldVals = []
pSecondaryGenShieldVals = []

When a generator is knocked offline all of the values are stored in it's list so they can be applied next time it comes online.

Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 24, 2011, 03:09:26 PM
Quote
Sweeping aside the fact that I said I was going through Python documentation and hadn't even heard of "type casting".

You claim to have certain C/C++ programming experience, this is one of the basics in programming in C# or C++. You seem to lack the basic understanding of OOP principles.

Quote
I am working on a way to store all the shield values of each shield generator in two lists.
pPrimaryGenShieldVals = []
pSecondaryGenShieldVals = []
When a generator is knocked offline all of the values are stored in it's list so they can be applied next time it comes online.

To store the values I recommend using a dictionary, key should be an ObjectId and value the shield values. This way in the future you will be able to use this script for AI ships also.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 24, 2011, 03:41:24 PM
You claim to have certain C/C++ programming experience, this is one of the basics in programming in C# or C++. You seem to lack the basic understanding of OOP principles.
I wasn't lying, I have done some things in C and C++ but never really covered the whole language. I admit it was wrong to simply say I had experience and not give any indication of just how much experience. I didn't intend to try and make myself seem smarter than I really was (especially since it's self-defeating), sorry  :facepalm: :doh:

Good point with the dictionary, I will use it instead of two seperate lists  :angel
Can you please elaborate on why specifically using a dictionary will allow me to use this script with AI ships? Currently the script works quite well for the AI Scimitar in BC 1.1; that is how I have been testing the script.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 24, 2011, 04:05:27 PM
Code: [Select]
lStats = [90, 90, 90, 90, 90, 90] # you can store only the stats for one ship
dStats = {8090 : [90, 90, 90, 90, 90, 90], 8091 : [90, 90, 90, 90, 90, 90]} # you store the values for multiple ships.

So you go on and simply call
Code: [Select]
dStats[pShip.GetObjID] to get the stored status. I thought it was pretty much self explanatory.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on September 24, 2011, 04:50:08 PM
I respect your knowledge and position within the BC modding scene so I don't mean to come across as rude or unappreciative when I say:

The script already appears to work for the QB Scimitar AI (in my version of BC at least). I mean I am in QB and the enemy AI Scimitar's Primary/Secondary shields are working so telling me that the use of a dictionary over a list is good because it allows the script to work with AI isn't self-explanatory.

Of course I will now use the dictionary data type now that I know you meant "working with AI" in the context of the script being able to store multiple shield values of not just the two shield generators of a single ship but the shield values for multiple ships.

Anticipating the scripts completion I thank you (USS Sovereign) and Defiant for all of the time you have spent with me on this. I also thank anyone else who chipped in to guide this newbie through the perils of the Python trail in BC.


EDIT:
No doubt anyone with more experience could have done this script much better than me in a fraction of the time but what the hell. It's been an experience and I guess everyone has to start somewhere. In retrospect I didn't really do much by myself, the script was generously given to me by  :angel Defiant :angel then he and  :angel USS Sovereign :angel told me how to do just about everything. It's not a complaint, just an acknowledgement.

I will reply back when the script is done.
Title: Re: BC 1.1 - Secondary shield generators
Post by: JimmyB76 on September 24, 2011, 05:36:15 PM
every excellent scripter started off one day from being brand new...  it is all about patience, and diligence and the desire to know more, and youll find yourself getting better and better!
shame you werent around the bc scene a few years ago when Sov was teaching new scripters alot about BC scripting...  over at BCS forums, there was about a dozen people he taught in many lessons from the very basic to more and more complex, there was a forum called Scripter Training Corps - youd have excelled im sure!   the forum is still there, just archived... 

just keep at it, what youre doing, and keep asking questions, and youll learn so much in the process and perhaps it could be the beginning of something youll enjoy doing and then wind up make alot of cool scripts for the BC community :)

personally, when youve finished this script im hoping youll release it for everyone to enjoy :)
Title: Re: BC 1.1 - Secondary shield generators
Post by: Mario on September 24, 2011, 05:37:39 PM
It is self-explanatory, you just don't see or understand the connection. The usage of lists as storage is pretty much used when you plan to develop a tech which is exclusive for the player ship or limited to 1 ship instance. Usage of a dictionary means that you plan to develop a tech which can be used by the AI. It is blindingly obvious that you cannot use a list to fetch and store data for multiple ships.

You might want to also check if the shields are actually on. There are times from players perspective when the shields will not be turned on and you might not want to trigger your code.
 
Code: [Select]
pShields.IsOn()
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 01, 2011, 12:24:52 PM
I have to start off with an apology, I said i'd reply back when the script is finished and now I am replying back with an unfinished script. :doh:
I also have to apologise for how long I have been abscent since my last post. I have been trying to put in as much work on the script as I can but my full-time education has priority.

And I can't forget the MOTM nomination from USS Sovereign. :eek No emoticon available can express the surprise that hit me when I got the PM from JimmyB76. All I can say is it's very flattering but I don't consider myself ellegable given: the script was generously given to me by Defiant and I have done very little of the work by myself.

------------------------------------------------------------
Now moving onto the script.
(The script and a ConsoleTrackerDump.txt are attached)

I have made, what I consider to be, some big leaps since my last post and now. I have put down the all-important conditional statements logic that determines what shield generator is currently active and what shield generator is going to take over (if any), or turn off the shields altogether.
I have also worked out the FOR loop that goes through the players shields and stores and/or applies the new shield values (if necessary) when generators become operational/disabled.

To be straight to the point and try not draw out the post to an essay (a habit of mine) I will hand out the reasons and problems for why the script is ready for use.
WARNING: The script is quite messy since I threw in print statements all over the place to find out what's going on. I've also constructed quite a tree of IF ELSE IF ... statements, although hopefully the comments will keep you on track.

PROBLEMS WITH THE SCRIPT:

1) Innaccurate shield values being assigned due to incorrect ShieldPercentage value.
When a generator goes offline I store the values of all it's shields so they can be loaded and applied when (IF) that generator comes back online. In order to do this however I have to store the current values and NOT the maximum HP file values.

First I need the percentage strength of the current shield being worked on in the FOR loop. I do this differently depending on whether the script is running for the first time or not.
For the first run I get it on line 146 with:
Code: [Select]
ShieldPercentage = ShieldGenerators[0].GetSingleShieldPercentage(Shield)After the first run I get it on line 163 with:
Code: [Select]
ShieldPercentage = pShields.GetSingleShieldPercentage(Shield)
Then I take this percentage value and use it to calculate the current strength of the current shield.
I do this on lines:
173 (storing current secondary generator shield values)
Code: [Select]
pSecondaryShieldVals[Shield] = pSecondaryGen.GetMaxShields(Shield) / 100 * ShieldPercentage * 100186 (storing current primary generator shield values)
Code: [Select]
pPrimaryShieldVals[Shield] = pDisabledObject.GetMaxShields(Shield) / 100 * ShieldPercentage * 100
As you can see I am using the standard mathematical percentage formula: ((number / 100) * percentage) to work out what the real strength of the current shield is based on the current percentage value stored in variable ShieldPercentage.

The ShieldPercentage variable isn't very reliable. If you look at line 317 of ConsoleTrackerDump.txt you will see that in the scenario the shield generator is being disabled because both fake generators are offline; the primary generator has just been disabled and secondary is also offline.
The script should be using ShieldPercentage to calcualte the current strength of the current shield and store it, instead though because ShieldPercentage is 1.0 (100%) the maximum shield strength is being stored instead of it's current ingame damaged strength.

1a) Tactical display not correct. The ingame strength of all shields is shown as 100%, even when the correct values are loaded.

I put this down as 1A because it's tied in with the ShieldPercentage problem. Most of the time you will find, if you ran the script and looked at the log from Console Tracker, that the current strength of the shield is being calculated, recorded, loaded and applied correctly.
However you will go back ingame and see that the shield display gives all shields in GREEN status, implying 100% strength when in fact they are just as weak or strong as when the generator was disabled. Having downloaded Defiants ShieldPercentages mod I have double confirmation of this as every shield gives it's percentage value at 100%

I wonder, can I calcualte the current percentage strength value of the shield as well as the shield strength values? If so could I use it to manually set the SingleShieldPercentage value and thus force the tactical display to show the correct percentage strength?

There is a:
Code: [Select]
pShields.GetSingleShieldPercentage(Shield)but is there?
pShields.SetSingleShieldPercentage(ShieldPercentage)


IMPROVEMENTS & TO-DO:

2) Expand the scope of the script through the use of dictionaries and objectIDs, allowing it to work with an unlimited number of ships & shield generators in QB.

I will need a data structure something such as:
Code: [Select]
[allShips]
  [ship]
    [primaryGenVals]
    [secondaryGenVals]
  [ship]
    [primaryGenVals]
    [secondaryGenVals]
  [ship]
    [primaryGenVals]
    [secondaryGenVals]
  [ship]
    [primaryGenVals]
    [secondaryGenVals]

I would then need to access it in a way similar to:
allShips[shipID[primaryGenVals]]
allShips[shipID[secondaryGenVals]]

How can I possibly write the script to manage a potentially unlimited amount of ships, and further more, continue to accurately decide what generators on each ship are ON/OFF and take appropraite action?

Bear in mind that the script is called when: player gets a new ship, a (any) subsystem is disabled or operational.

(MAYBE) TO-DOs
3) Cover the CTRL + SHIFT + R scenario.

Do I need to reset shield strengths for both generators or it's gonna trip over when they force repair both generators at the same time. How do I know if the player hits those three keys?

4) Add a delay value that is accessible through the Foundation plugin so the user can choose how long it takes for the shields to switchover.

I simply have no idea how to add a real-world time delay to a script.
What if an insanely large amount of time is given for the switchover?
What if during the delay between switchover a generator is repaired or disabled? Such as primary getting disabled, a delay of N seconds starting then the primary comes back online - OR the secondary (which is all set to takeover) is disabled?

It's nice to open up the script a bit and allow some room for configuration. I personally think that there should be absolutely no delay between switchover because you will be in a warzone and it'd be a serious design flaw for there to be a delay between generator switch-overs.

5) Foundation technologies?

Will shield modifiers work or will it have problems working on ships that use Primary and Secondary shields?
Can I allow users to apply different technologies to different generators? E.G: Regenerative shields when primary is active but normal shields for secondary?
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on October 01, 2011, 03:51:58 PM
Not replying to everything right now because I lost myself somewhere belong your post.

1. Shield settings do usually work. My guess is that there is still an error in the script..

2. Just look at dictionarys, you can use a ships id or name as keys.

3. You can use Game.InGodMode(), but I would ignore it because God mode is non standard and in god mode you can't die anyway.
Time is expensive, better concentrate for the important parts.

4. Same as 3. Get it working before expanding it.

5. When your script is done get some users to test it woth other mods.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 01, 2011, 04:17:57 PM
Sorry about the post length. I look at it myself and think "woah, that's long".

I am burnt out right now and won't look at another line of Python until tomorrow; my eyes hurt and this room must be => 30 degrees C.

Your most probably right about the ShieldPercentages thing I droned on about in 1)
The fact that the MAX super strong values are being stored when both targetable generators are disabled and there should be no shields. It shows that I messed up somewhere in the conditional statements, a very frustrating error considering the time I went running over and over that IF ELSE tree :facepalm:

The tactical display thing I don't want to drone on about. However I am sure that even when the script applies to correct stored values, the display shows everything at 100%  :lostit:

I promise I will look at dictionaries myself and make a real effort to get to grips with them. However can you just assure me that you can construct so many lists of values inside a single variable like that?
I will need to be able to add and remove lists from the master allShips to facilitate the creation and destruction of ships. Don't want the script to waste memory by keeping values of dead ship objects (ships destroyed in battle).

Your right about prioritising, a required skill of paramont importance in computing. However the CTRL + SHIFT + R stays on my list because I want to cover as many angles as possible. Don't want this script to ruin someones gaming session because I was lazy.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on October 02, 2011, 02:36:40 AM
Line 109:
Code: [Select]
pShields.GetProperty().SetDisabledPercentage(100.0)
This value is a number between 0 and 1.

Line 173:
Code: [Select]
# using it's percentage, store the current  shield value of secondary shield generator
pSecondaryShieldVals[Shield] = pSecondaryGen.GetMaxShields(Shield) / 100 * ShieldPercentage * 100
What are you doing here?

MaxShield is a value, e.g. strength of 10000 hitpoints, ShieldPercentage a number between 0 and 1.
So when the Shield is on 50% you store 10000/100 * 0.5 * 100 = 5000.
The formula is actually the same as just doing pSecondaryGen.GetMaxShields(Shield) * ShieldPercentage

ok now you have the value, later line 190 you restore it:
Code: [Select]
ShieldStrength = pSecondaryShieldVals[Shield]
..
pShields.GetProperty().SetMaxShields(Shield, ShieldStrength)
...
pShields.SetCurShields(Shield, ShieldStrength)
What happens here?

1. Somewhere lowered your shield value to 50%. Max Shield was 10000, so you save the value of 5000 in line 173.
2. In line 190 you restore the value later. But instead of setting MaxShield to 10000 and CurShield to 0.5 you set both to 5000!

-

In Python everything is an object. Dictionaries are there to map objects, so yes. You can even store dictionaries in dictionaries.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 03, 2011, 07:01:26 PM
Ha HAA! YES! Success!
  :angel Defiant :angel

What was I thinking? Setting both the MaxShield and CurShield to the same values. No wonder the shield percentages were coming out as 100%

The shield values are being swapped, stored, loaded and now also displayed in the tactical display correctly.

Now... how can I cover the CTRL + SHIFT + R ? I already tried it on the current version and well...it doesn't like it. A leap of faith is how i'd describe the scripts execution when you hit the three button combination.

It would be nice to get all the logic down and cover all the angles before using dictionaries and object IDs to permit any number of ships with Primary/Secondary shields.

Speaking of the dictionaries, is there an event handler for the destroy ship event?
When I get round to expanding, I will need one if I am to remove the values of a ships shields from the master dictionary - if not removed the dictionary will grow and grow.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on October 04, 2011, 06:43:23 AM
God mode:
Look at TacticalInterfaceHandlers.py for godmode.

Destroy:
See http://kobmaru.de/svn/trunk/scripts/Custom/QBautostart/BorgEmergEscape.py for Exploding event.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 05, 2011, 03:04:32 PM
Just so you know I havn't abandoned the script here's an

UPDATE:
 :yay: The script can now handle a potentially unlimited number of primary/secondary generator ships! :yay:
The script now uses a dictionary and the unique ID of each object(ship) to store shield values. Also, when a ship with Primary/Secondary shields is destroyed it's shield values are removed from the dictionary.


CURRENTLY:
CTRL + SHIFT + R doesn't want to play ball :nono:
I setup a working event handler for the insta-repair event (ctrl+shift+r) but when it calls RedefineShieldGenerators() it doesn't get past the first print statement. This is (i think) obviously because GetAllShieldGenerators() is being naughty and returning an empty retList (list of fake shield generators).
Why does GetAllShieldGenerators() work 99% of time, but break when ShipInstaRepair() calls it?

Check out the attached log file, it gets really wierd from line 330 (when the ctrl+shift+r handler fires) onwards. The handler fires three times (when I hit insta-repair once ingame!) but RedefineShieldGenerators() dies before it does anything because of:
Code: [Select]
if NumTotalGenerators == 0:
                return
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 09, 2011, 09:48:56 AM
I know I know it's a double post, sorry. :P

I sorted out the stupid problem I mentioned. Every event handler other than ShipInstaRepair() was using:
Code: [Select]
pShip = App.ShipClass_Cast(pEvent.GetDestination())to cast the pShip argument for GetAllShieldGenerators() However the pEvent for ShipInstaRepair() is what I technically describe as "weird" so long story short I had to cast pShip for GetAllShieldGenerators() using:
Code: [Select]
pShip = App.ShipClass_Cast(pShip.GetTarget())
------------------------------------
My approach to covering CTRL + SHIFT + R is simple. Use the ShipInstaRepair() event handler to reset all the shield values for both fake generators to their maximum values & force fake primary to become the active generator. I do this by simply calling RedefineShieldGenerators() with the firstScriptRun (3rd arg) as 1.

The handler works just how I want it to, despite firing multiple times even though I hit CTRL+SHIFT+R only once ingame!


NOW

Some things to let you know.
#1: In the QB scenario (for simplicity & the log size) there is only one ship with primary/secondary generators; a scimitar.
#2: It is SubsystemOperational() that really screws things up.

The log reflects that I:
(1)disabled the (targetable) primary generator,
(2)disabled the (targetable) secondary generator.
(3)Hit CTRL+SHIFT+R,
(4)then disabled the (targetable) primary generator.
(5)Exited game.

Going by the attached log.
(1)
Line 106 to 178 - Primary gen is disabled, it's values are stored and secondary takes over.
(2)
Line 182 to 224 - Secondary gen is disabled, it's values are stored and the real hidden gen is disabled.
(3)
>Line 228 to 281 - ShipInstaRepair() fires for the first time. RedefineShieldGenerators() is called and runs as it should; re-setting all shields to their max values, making the fake primary gen the activeShieldGen.
 :lostit: !LOOP START! :lostit:
Line 285 to 337 - ShipInstaRepair() fires. RedefineShieldGenerators() is called and runs as it should.
Line 341 to 393 - ShipInstaRepair() fires. RedefineShieldGenerators() is called and runs as it should.
Line 397 to 449 - ShipInstaRepair() fires. RedefineShieldGenerators() is called and runs as it should.
Line 453 to 505 - ShipInstaRepair() fires. RedefineShieldGenerators() is called and runs as it should.
Line 509 to 561 - ShipInstaRepair() fires. RedefineShieldGenerators() is called and runs as it should.
Line 565 to 617 - ShipInstaRepair() fires. RedefineShieldGenerators() is called and runs as it should.
 :lostit: !LOOP END! :lostit:

>Line 565 to 617 SubsystemOperational() fires. RedefineShieldGenerators() is called (firstScriptRun = 0) which proceeds to overwrite the dictionary values for the Secondary gen with 0 and make fake Primary gen the activeShieldGen.
>Line 697 to 706 SubsystemOperational() fires. RedefineShieldGenerators() is called (firstScriptRun = 0), but it knows Primary is already on so does nothing.

(4)
Line 710 to 782 - Primary gen is disabled, it's values are stored and secondary takes over.
TA - DA! Ingame evidence that the script has fallen flat on its face, Primary offline, Secondary online and no shields!
(5)
Line 783 to EOF - I destroy the scimitar and exit game!

---------------------------------------------------------------------------------------
Why is there a loop with ShipInstaRepair() ?
How do I stop SubsystemOperational() from firing and screwing things up! ?

*Previews post* Wow! That is long!  :doh: Sorry
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on October 10, 2011, 03:34:01 AM
Do you reset your global values on repair?
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 10, 2011, 08:31:55 AM
I had to do a little guess work on what you meant by
Quote from: Defiant
global values on repair?
so don't shoot me if I guessed wrong.  :idk:

I assume you are talking about the master allShips dictionary array because that is the only (intentionally created) global variable, that I know of, in the script. I don't set the shield values to 0 when ShipInstaRepair() fires. All it does is call RedefineShieldGenerators() to reset all the shield values for the repaired ship to their HardPoint MAX values.

The log shows clear evidence that RedefineShieldGenerators() does its job correctly.
>Line 228 to 281 - ShipInstaRepair() fires for the first time. RedefineShieldGenerators() is called and runs as it should; re-setting all shields to their max values, making the fake primary gen the activeShieldGen.

When RedefineShieldGenerators() is called from SubsystemOperational() it gives an argument firstScriptRun = 0. This is what screws things up.
I DO NOT want the operational handler to get involved when ShipInstaRepair() fires because ShipInstaRepair() does all the work that needs to be done.

Because RedefineShieldGenerators() is called with firstScriptRun = 0 after the shields have been setup, it goes crazy with the shield values (setting them to 0).
>Line 565 to 617 SubsystemOperational() fires. RedefineShieldGenerators() is called (firstScriptRun = 0) which proceeds to overwrite the dictionary values for the Secondary gen with 0 and make fake Primary gen the activeShieldGen.
Just need to stop the Operational handler getting involved when CTRL+SHIFT+R handler has done it's work and there should be no problems. ... I hope  :(
Title: Re: BC 1.1 - Secondary shield generators
Post by: KrrKs on October 10, 2011, 11:49:47 AM
It has been some time since I tried scripting something, so this is most likely not the optimal approach,
but you could add a global boolean per Ship.
If InstaRepair is called it could set this Boolean to false, and initiate a Timer that sets it back to true after a short time (or the other way around).
In SubsystemOperational() you could then check the this variable to see if InstaRepair was just executed on that ship.

But I don't know how repeated usage of that Timer would influence BC's Stability.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 10, 2011, 02:35:12 PM
Giving a specified amount of time in which the Operational handler can't fire.... hmmm. I'm not exactly in a position of BC Python power to crush your idea since i'm a noob beginner. However, I see problems because the handler would be unable to fire when another ships primary/secondary shield generators become active. It would effectively be saying to the script "this ship is more important, ignore everyone else for X long".

Also, do the event handlers stack up? I mean if an event (such as CTRL+SHIFT+R) causes lots of Operational handler fires, don't they all stack up and wait their turn? It certainly looks that way at the moment because the Operational handler fires twice when both generators are currently disabled and the user hits CTRL+SHIFT+R.

My problem is I don't have any insight into how BC handles things. I've done some event driven stuff in VB ( :facepalm:) but have no view of the environment the script is being executed in; other than QuickBattle, of course..
Title: Re: BC 1.1 - Secondary shield generators
Post by: Defiant on October 12, 2011, 02:22:43 AM
Uhm, why do you even call RedefineShieldGenerators() on instant repair?

My guess is that you do not need to do anything special. Just clear your globals for this ship and handle it like you get a clean new one and set your shield values to the primary one.
Title: Re: BC 1.1 - Secondary shield generators
Post by: Bat66wat6 on October 12, 2011, 06:41:58 AM
That is correct, all I need to do is set the globals for the ship to their max values and set primary as the active shield generator. This is exactly what RedefineShieldGenerators() does when you call it with the 3rd argument as 1 (firstScriptRun = 1).

RedefineShieldGenerators() is the only function that actually *does* anything to the shield values, and it runs just fine like I wanted when instant repair handler calls it.

I need a way to stop the operational handler firing when instant repair fixes the shield generators because when it calls RedefineShieldGenerators() it calls it with firstScriptRun = 0. As a result the Redefine function gets it wrong and overwrites the shield values like I explained

>Line 565 to 617 SubsystemOperational() fires. RedefineShieldGenerators() is called (firstScriptRun = 0) which proceeds to overwrite the dictionary values for the Secondary gen with 0 and make fake Primary gen the activeShieldGen.
>Line 697 to 706 SubsystemOperational() fires. RedefineShieldGenerators() is called (firstScriptRun = 0), but it knows Primary is already on so does nothing.

(4)
Line 710 to 782 - Primary gen is disabled, it's values are stored and secondary takes over.
TA - DA! Ingame evidence that the script has fallen flat on its face, Primary offline, Secondary online and no shields!
(5)

Note that when the operational handler first fires and sets the primary generator as the active shield generator, it IS ALREADY the active shield generator because RedefineShieldGenerators() has already ran (firstScriptRun = 1) and set everything up correctly.


EDIT:
14/10/11
UPDATE
Not sure if this is the best way (most efficient) but I got a function down that checks if ShipInstaRepair() has just ran by first checking if both generators are operational. Then it runs through all the shield values in allShips for the given ship to see if there all at max strength.

The function returns 1 (true) if InstaRepair() has just ran or 0 (false) if it hasn't. I use it ShipInstaRepair() to stop it calling RedefineShieldGenerators() over and over to the same thing again and again! I also use it in the operational handler so it doesn't run the redefine function and mess up the values.

What do you think?
Code: [Select]
# check if ShipInstaRepair() has already ran by checkingif both generators are operational & all shields at full strength
def InstaRepairAlreadyRan(pShip):
ShieldGenerators = GetAllShieldGenerators(pShip)
if ShieldGenerators[0].IsDisabled() or ShieldGenerators[1].IsDisabled():
return 0
else:
lShields = GetPrimarySecondaryGenNames(pShip)
pPrimaryGen = MissionLib.GetSubsystemByName(pShip, lShields[0])
pSecondaryGen = MissionLib.GetSubsystemByName(pShip, lShields[1])
pPrimaryGen = App.ShieldClass_Cast(pPrimaryGen)
pSecondaryGen = App.ShieldClass_Cast(pSecondaryGen)
shipID = pShip.GetObjID()
i = 0
while(i < 6):
if not allShips[shipID][0][i] == pPrimaryGen.GetMaxShields(i):
return 0
if not allShips[shipID][1][i] == pSecondaryGen.GetMaxShields(i):
return 0
i = i + 1
return 1

It seems to work quite well from what both the log, and ingame, gives out.

Line 376 down, the secondary shield values  :)

Hoping to keep the script tight and quick (less lag!) I was hoping for something less crude than looping through every shield value. I can live with it but is there a better way?


EDIT:
14/10/11 two

You can use CTRL+SHIFT+K to disable a generator without damaging any of the shields, as a result my InstaRepairAlreadyRan() function returns 1 (true) and SubsystemOperational() doesn't run when the generator comes back online!
Damn it!  :banghead: