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 05-14-07, 03:35 PM   #1
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

There are quite a few small examples in the README. Also, you can define new functions for future use by adding them to the init.py file (see the file for a few examples).

Other than that, yes, copy/paste is the best way. I wanted something simple for the non-programmer and that wasn't too hard for me to code. If there is enough interest, I can add a second interface where you can just run code directly from a file.
mcoca is offline   Reply With Quote
Old 05-16-07, 06:36 PM   #2
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

I've found a "bug" when generating "zigzag's" that cross 180 longitude, it will generate positions that go around the world vice crossing the dateline correctly
lurker_hlb3 is offline   Reply With Quote
Old 05-17-07, 06:25 AM   #3
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by lurker_hlb3
I've found a "bug" when generating "zigzag's" that cross 180 longitude, it will generate positions that go around the world vice crossing the dateline correctly
Yes, that makes sense (I actually sort of considered it would happen, but didn't think it serious). I'll check where the boundary is (in coordinates) and add the appropiate safeguards for 0.4.

Thanks,
mcoca is offline   Reply With Quote
Old 05-18-07, 03:27 PM   #4
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

having a problem with "cargoExt & cargoInt". When I use/change them get "error" saying that these item are read only. Was using them in contection with editing / creating merchants.


also


is there code to "randomly" selecting "crewratings" ?
lurker_hlb3 is offline   Reply With Quote
Old 05-18-07, 03:59 PM   #5
tater
Navy Seal
 
Join Date: Mar 2007
Location: New Mexico, USA
Posts: 9,023
Downloads: 8
Uploads: 2
Default

^^^ wow, that would be an amazing set of functionality. The ability to pick a number of objects (which it does now) then repopulate some fields with values from a list of possible values randomly.

You can do this after a fashion now by having a few ships of the same type with a % chance of appearing, each with a different crew rating, the only problem being you might very well see ALL of them at once. Sometimes you might want only 1 ship, but of variable skill (or internal/external cargo, etc)
tater is offline   Reply With Quote
Old 05-18-07, 04:07 PM   #6
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

Here some test code that I'm working on, it's for Japanese Convoys ( 41a / 42a /42b /43a / 44a / 44b.

I've play test this and some other code for Merchants / TF / SubHunters, and let be the one to tell you, "patrols" are no longer boring


Code:
if group.groupName.find("Convoy") != -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 ()
    i = group.units.iterator ()
    for unit in i:
        if unit.type == UnitType.DESTROYER:
            i.remove ()
if group.groupName.find("Convoy") != -1:
   if group.groupName.find("Jap") != -1:
     if group.gameEntryDate.after(Mission.date("19411101")) and group.gameEntryDate.before(Mission.date("19420831")):
     #merchant 1
        mer=RndUnit.createCargo("Japan", 100)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 2
        from random import randint
        padd= randint(65,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 3
        from random import randint
        padd= randint(45,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 4
        from random import randint
        padd= randint(35,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #tanker 1
        from random import randint
        padd= randint(80,100)
        tkr=RndUnit.createTanker("Japan", padd)
        tkr.configurationDate=group.gameEntryDate
        group.units.add(tkr)
if group.groupName.find("Convoy") != -1:
   if group.groupName.find("Jap") != -1:
     if group.gameEntryDate.after(Mission.date("19420831")) and group.gameEntryDate.before(Mission.date("19430831")):
     #merchant 1
        mer=RndUnit.createCargo("Japan", 100)
        mer.number=2
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 2
        from random import randint
        padd= randint(65,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 3
        from random import randint
        padd= randint(45,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 4
        from random import randint
        padd= randint(35,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #tanker 1
        from random import randint
        padd= randint(80,100)
        tkr=RndUnit.createTanker("Japan", padd)
        tkr.configurationDate=group.gameEntryDate
        group.units.add(tkr)
     #tanker 2
        from random import randint
        padd= randint(35,65)
        tkr=RndUnit.createTanker("Japan", padd)
        tkr.configurationDate=group.gameEntryDate
        group.units.add(tkr)
     #escorts
        from random import randint
        padd= randint(75,85)        
        escort=RndUnit.createWarship("Japan", UnitType.DESTROYER, True, padd)
        escort.configurationDate=group.gameEntryDate
        group.units.add(escort)
if group.groupName.find("Convoy") != -1:
   if group.groupName.find("Jap") != -1:
    if group.gameEntryDate.after(Mission.date("19430831")) and group.gameEntryDate.before(Mission.date("19440531")):
     #merchant 1
        mer=RndUnit.createCargo("Japan", 100)
        mer.number=2
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 2
        from random import randint
        padd= randint(65,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 3
        from random import randint
        padd= randint(45,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 4
        from random import randint
        padd= randint(35,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #tanker 1
        from random import randint
        padd= randint(80,100)
        tkr=RndUnit.createTanker("Japan", padd)
        tkr.configurationDate=group.gameEntryDate
        group.units.add(tkr)
     #tanker 2
        from random import randint
        padd= randint(35,65)
        tkr=RndUnit.createTanker("Japan", padd)
        tkr.configurationDate=group.gameEntryDate
        group.units.add(tkr)
     #escorts
        escort=RndUnit.createWarship("Japan", UnitType.DESTROYER, True, 100)
        escort.configurationDate=group.gameEntryDate
        escort.crewRating = CrewRating.VETERAN
        group.units.add(escort)
        from random import randint
        padd= randint(75,85)        
        escort=RndUnit.createWarship("Japan", UnitType.DESTROYER, True, padd)
        escort.number=1
        escort.configurationDate=group.gameEntryDate
        escort.crewRating = CrewRating.VETERAN
        group.units.add(escort)
        from random import randint
        padd= randint(45,85)   
        escort=RndUnit.createWarship("Japan", UnitType.DESTROYER, True, padd)
        escort.configurationDate=group.gameEntryDate
        escort.crewRating = CrewRating.ELITE
        group.units.add(escort)
if group.groupName.find("Convoy") != -1:
   if group.groupName.find("Jap") != -1:
     if group.gameEntryDate.after(Mission.date("19440530")) and group.gameEntryDate.before(Mission.date("19450831")):
     #merchant 1
        mer=RndUnit.createCargo("Japan", 100)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 2
        from random import randint
        padd= randint(65,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 3
        from random import randint
        padd= randint(45,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #merchant 4
        from random import randint
        padd= randint(35,85)
        mer=RndUnit.createCargo("Japan", padd)
        mer.configurationDate=group.gameEntryDate
        group.units.add(mer)
     #tanker 1
        from random import randint
        padd= randint(80,100)
        tkr=RndUnit.createTanker("Japan", padd)
        tkr.configurationDate=group.gameEntryDate
        group.units.add(tkr)
     #tanker 2
        from random import randint
        padd= randint(35,65)
        tkr=RndUnit.createTanker("Japan", padd)
        tkr.configurationDate=group.gameEntryDate
        group.units.add(tkr)
     #escorts
        escort=RndUnit.createWarship("Japan", UnitType.DESTROYER, True, 100)
        escort.configurationDate=group.gameEntryDate
        escort.crewRating = CrewRating.VETERAN
        group.units.add(escort)
        from random import randint
        padd= randint(75,85)        
        escort=RndUnit.createWarship("Japan", UnitType.DESTROYER, True, padd)
        escort.crewRating = CrewRating.VETERAN
        escort.configurationDate=group.gameEntryDate
        group.units.add(escort)    


if group.columns > 1:
     group.columns = 2

if group.spacing > 1:
     from random import randint
     group.spacing = randint(500,995)

if group.groupName.find("Convoy") != -1:
   if group.groupName.find("Jap") != -1:
       if group.gameEntryDate.before(Mission.date("19421231")):
           from random import randint
           group.spawnProbability = randint(25,45)
       elif group.gameEntryDate.before(Mission.date("19431231")):
           from random import randint
           group.spawnProbability = randint(35,85) 
       elif group.gameEntryDate.before(Mission.date("19441231")):
           from random import randint
           group.spawnProbability = randint(45,90)
       else:
           from random import randint
           group.spawnProbability = randint(35,50)



if group.repeatIntervalMinutes > 1:
           from random import randint
           group.repeatIntervalMinutes = randint(3000,10000)


if group.autoReportProbability > 1:
           from random import randint
           group.autoReportProbability = randint(5,25)

if group.autoReportInterval > 1:
           from random import randint
           group.autoReportInterval = randint(1440,9999)

if group.columns > 1:
     group.columns = 2

if group.spacing > 1:
     from random import randint
     group.spacing = randint(500,995)

i = group.waypoints.iterator ()
for waypoint in i:
    if waypoint.loopProbability > 0:
        from random import randint
        waypoint.loopProbability = randint(2,8)

i = group.waypoints.iterator ()
for waypoint in i:
    if waypoint.radius > 0:
        waypoint.radius = 0

i = group.waypoints.iterator ()
for waypoint in i:
    if waypoint.length > 500*1852:
        zigZagToWaypoint(waypoint,i,0,100)

i = group.waypoints.iterator ()
for waypoint in i:
    if waypoint.length > 99*1852:
             from random import randint
             angle= randint(15,35)
             distance= randint(12,50)
             zigZagToWaypoint(waypoint,i,angle,distance)

from random import randint
for waypoint in group.waypoints:
    waypoint.speed = randint(7,12)

Last edited by lurker_hlb3; 05-18-07 at 04:22 PM.
lurker_hlb3 is offline   Reply With Quote
Old 05-18-07, 04:44 PM   #7
tater
Navy Seal
 
Join Date: Mar 2007
Location: New Mexico, USA
Posts: 9,023
Downloads: 8
Uploads: 2
Default

Damn.

I wish I knew half of what that was doing, looks pretty interesting, though.
tater is offline   Reply With Quote
Old 05-18-07, 04:47 PM   #8
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by lurker_hlb3
Here some test code that I'm working on, it's for Japanese Convoys ( 41a / 42a /42b /43a / 44a / 44b.

I've play test this and some other code for Merchants / TF / SubHunters, and let be the one to tell you, "patrols" are no longer boring.
Wow, those are pretty extensive changes. I have created a monster!

Seeing the kind of things people are doing, next version will definitely have a "run script from file" option. Let's see if I have time to put it together tomorrow.
mcoca is offline   Reply With Quote
Old 05-18-07, 04:42 PM   #9
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by lurker_hlb3
having a problem with "cargoExt & cargoInt". When I use/change them get "error" saying that these item are read only. Was using them in contection with editing / creating merchants.
I expanded the internal names to "internalCargo" and "externalCargo". I have no idea why the error is so silly...

Quote:
is there code to "randomly" selecting "crewratings" ?
Not per se, but it's really easy to create your own:

Code:
unit.crewRating=choice((CrewRating.POOR, CrewRating.NOVICE, CrewRating.COMPETENT))
That will select a random element from that list. Add or remove elements at will. You can also edit init.py to add a function that does that as shorthand.
mcoca is offline   Reply With Quote
Old 07-12-07, 06:28 PM   #10
tater
Navy Seal
 
Join Date: Mar 2007
Location: New Mexico, USA
Posts: 9,023
Downloads: 8
Uploads: 2
Default

Quote:
Originally Posted by mcoca
Quote:
Originally Posted by lurker_hlb3
having a problem with "cargoExt & cargoInt". When I use/change them get "error" saying that these item are read only. Was using them in contection with editing / creating merchants.
I expanded the internal names to "internalCargo" and "externalCargo". I have no idea why the error is so silly...

Quote:
is there code to "randomly" selecting "crewratings" ?
Not per se, but it's really easy to create your own:

Code:
unit.crewRating=choice((CrewRating.POOR, CrewRating.NOVICE, CrewRating.COMPETENT))
That will select a random element from that list. Add or remove elements at will. You can also edit init.py to add a function that does that as shorthand.
Can you create a list with the same entry twice?

For example:
Code:
unit.crewRating=choice((CrewRating.COMPETENT, CrewRating.COMPETENT, CrewRating.COMPETENT, CrewRating.COMPETENT, CrewRating.COMPETENT, CrewRating.COMPETENT, CrewRating.VETERAN, CrewRating.VETERAN, CrewRating.VETERAN, CrewRating.ELITE))
The idea would be that without other coding it would quickly give a 10% chance of Elite, 30% vet, 60% Competant.

tater
tater 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 12:23 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.