SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SH4 Mods Workshop
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 06-13-07, 12:35 PM   #91
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Hey everyone, sorry the promised release didn't arrive.

Actually, I have all the coding changes ready, it only needs documenting the new features. Unfortunately, real life interrupted me, and I never got around to it. Let's see if I can write something tonight and release.

Meanwhile, tater, it's really nice to see people actually using this in released mods
mcoca is offline   Reply With Quote
Old 06-13-07, 12:36 PM   #92
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by tater
Hey, how would I code it to randomize waypoint.speed, but only if the speed for the given waypoint is > some number (say 5)?

I tried:
Code:
from random import randint
i = group.waypoints.iterator ()
for waypoint in i:   
    if waypoint.speed > 5:
    waypoint.speed = randint(6,10)
but it doesn't work
You are missing an indentation (white space counts in python!):

Code:
from random import randint
i = group.waypoints.iterator ()
for waypoint in i:   
    if waypoint.speed > 5:
        waypoint.speed = randint(6,10)
mcoca is offline   Reply With Quote
Old 06-13-07, 12:46 PM   #93
tater
Navy Seal
 
Join Date: Mar 2007
Location: New Mexico, USA
Posts: 9,023
Downloads: 8
Uploads: 2
Default

thx! got it!
tater is offline   Reply With Quote
Old 06-13-07, 01:25 PM   #94
wildchild
Chief
 
Join Date: Aug 2006
Location: some where in the deep blue sea
Posts: 318
Downloads: 0
Uploads: 0
Default

Will This Work On Sh3 :d
__________________
come one and all stand together and fight from the deep
CLICK HERE
wildchild is offline   Reply With Quote
Old 06-13-07, 01:42 PM   #95
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by wildchild
Will This Work On Sh3 :d
I think SH4 added some fields to the SH3 file format. Since the program expects them to be there, it probably won't work. However, making a SH3-compatible version should be very easy.

If someone tries it, just let me know.
mcoca is offline   Reply With Quote
Old 06-13-07, 05:15 PM   #96
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

New version released at last. See first post for details.
mcoca is offline   Reply With Quote
Old 06-13-07, 08:06 PM   #97
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

found a bug using the "script" option. Injected the following code using "script" option and software displayed "error" message. used the same in the "group change" field and software worked as designed

Code:
if group.groupName.find("Merchants") != -1:
    i = group.units.iterator ()
    for unit in i:
        if unit.type == UnitType.CARGO:
            i.remove ()
    i = group.units.iterator ()
    for unit in i:
        if unit.type == UnitType.TANKER:
            i.remove ()

also


request a working example of the following code

moveGroup(group,1000,2000)


and



i = mission.randomGroups.iterator ()
for group in i:
i.insert (group.clone ())


Thabks in advance

Last edited by lurker_hlb3; 06-13-07 at 08:27 PM.
lurker_hlb3 is offline   Reply With Quote
Old 06-14-07, 03:06 AM   #98
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by lurker_hlb3
found a bug using the "script" option. Injected the following code using "script" option and software displayed "error" message. used the same in the "group change" field and software worked as designed

Code:
if group.groupName.find("Merchants") != -1:
    i = group.units.iterator ()
    for unit in i:
        if unit.type == UnitType.CARGO:
            i.remove ()
    i = group.units.iterator ()
    for unit in i:
        if unit.type == UnitType.TANKER:
            i.remove ()
When you insert code in the "group change", the program turns it into something like this:

Code:
    i = mission.randomGroups.iterator ()
    for group in i:
        [[group change code]]
The script mode has no such loops defined, so you need to add them explicitly. In your case:

Code:
group_iter = mission.randomGroups.iterator ()
for group in group_iter:
    if group.groupName.find("Merchants") != -1:
        i = group.units.iterator ()
        for unit in i:
            if unit.type == UnitType.CARGO:
                i.remove ()
        i = group.units.iterator ()
        for unit in i:
            if unit.type == UnitType.TANKER:
                i.remove ()
The advantage of script mode is that you can write a complete program, including defining you own functions. So you write the previous code in this way (untested, may contain typos):

Code:
def removeShips (group, type):
    i = group.units.iterator ()
    for unit in i:
    if unit.type == type
        i.remove ()

group_iter = mission.randomGroups.iterator ()
      for group in group_iter:
    if group.groupName.find("Merchants") != -1:
        removeShips(group, UnitType.CARGO)
        removeShips(group, UnitType.TANKER)
Which is, IMO, much cleaner.

Quote:
request a working example of the following code

moveGroup(group,1000,2000)


and



i = mission.randomGroups.iterator ()
for group in i:
i.insert (group.clone ())
This happens when you write the docs from memory, sorry This script works fine on a sample mission with a single group:

Code:
i = mission.randomGroups.iterator ()
for group in i:
        clone=group.clone()
        moveGroup(clone, 100000, 100000)
        i.add(clone)
Hope this helps,
mcoca is offline   Reply With Quote
Old 06-14-07, 07:23 AM   #99
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

Tried this in the group change area

but gave the following error "unexpected error: java.util.ConcurrentModificationException:null

Code:
 i = mission.randomGroups.iterator ()
for group in i:
        clone=group.clone()
        moveGroup(clone, 100000, 100000)
        i.add(clone)
lurker_hlb3 is offline   Reply With Quote
Old 06-14-07, 07:31 AM   #100
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by lurker_hlb3
Tried this in the group change area

but gave the following error "unexpected error: java.util.ConcurrentModificationException:null

Code:
 i = mission.randomGroups.iterator ()
for group in i:
        clone=group.clone()
        moveGroup(clone, 100000, 100000)
        i.add(clone)
Yes, I know. With the cloning, I hit the limit of what I can do transparently by mixing loops in Java and Python (for the group change), without complicating things further. So, the cloning is only usable from the script mode.

There may be some way around it, but I'm satisfied with the current solution, since I think anyone making complex changes should be using the script mode anyway. If yuo want to find a fix, check the source (it's in src/net/sf/shbatcheditor/editor/changes/JythonRndGroupChange.java).
mcoca is offline   Reply With Quote
Old 06-14-07, 04:59 PM   #101
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

The problem I'm having right now is that there are not any "samples" of script code.
I've made some fairly complex changes with the scripts that I created with the last version.

Was able to get a lot of ideas from the "campaignchanges.py" when working with v0.3 how ever can't find the same with this version.

since my last post found out that the cloning only works with "script" mode and have hacked some of my old code to work with "scripts" based on one of your other post.

current problem is it doesn't like "from random import randint" call and throws out an error.


Request a set of example so I can get my bearing and start using you great tool


Thanks in Advance
lurker_hlb3 is offline   Reply With Quote
Old 06-14-07, 05:18 PM   #102
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by lurker_hlb3
Was able to get a lot of ideas from the "campaignchanges.py" when working with v0.3 how ever can't find the same with this version.

since my last post found out that the cloning only works with "script" mode and have hacked some of my old code to work with "scripts" based on one of your other post.

current problem is it doesn't like "from random import randint" call and throws out an error.
You are probably using it from inside a loop, and it doesn't like it (I was quite surprised that it worked in the past).

Quote:
Request a set of example so I can get my bearing and start using you great tool
Okay, as a general rule, a script should look like this:

Code:
# Imports at the top
from random import *

# Any function definitions you want to create:
def removeShips (group, type):
    i = group.units.iterator ()
    for unit in i:
    if unit.type == type
        i.remove ()def removeShips (group, type):

# Loop over the groups
i = mission.randomGroups.iterator ()
for group in i:
    # What used to be in the "group change" box, except for imports, goes here,
    # with the proper indentation
    removeShips(group, UnitType.CARGO)
    clone=group.clone()
    moveGroup(clone, 100000, 100000)
    i.add(clone)
You can, of course, be more creative: move the loop into a function defition, create several loops, etc. But that's the equivalent of what was going on before.

Hope this helps.
mcoca is offline   Reply With Quote
Old 06-14-07, 06:02 PM   #103
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

Thanks for your help, based on your last post was able to get one of my key scripts to now work in "script" mode.

PS

Hate the "White Space" rules, got so many "snytax" errors I though I was going put my fist through the monitor
lurker_hlb3 is offline   Reply With Quote
Old 06-14-07, 06:13 PM   #104
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by lurker_hlb3
Thanks for your help, based on your last post was able to get one of my key scripts to now work in "script" mode.

PS

Hate to "White Space" rules, got so many "snytax" errors I though I was going put my fist through the monitor
Get a good programming editor that supports python There must be a couple dozen free ones around.

And I know whitespace control can be frustrating. But so can be figuring out why the following C/C++/Java/C# code also increments negative numbers (trivial example follows):

Code:
if ( x > 0)
    x = x * 2;
    x = x + 1;
The first time you find that in someone else's code you have to debug, you'll miss python style control
mcoca is offline   Reply With Quote
Old 06-14-07, 07:00 PM   #105
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

Using "EditPad Pro" now vice "EditPad Lite", change out the other 5 scripts in about 10 minutes

Thanks again for the help

Last edited by lurker_hlb3; 06-14-07 at 07:42 PM.
lurker_hlb3 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 07:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 1995- 2025 Subsim®
"Subsim" is a registered trademark, all rights reserved.