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

Almost forgot! Please consider this an "undocumented feature" for the moment, but for those who are feeling brave, the distribution includes the entire python standard library, meaning you can do all types of nifty things, including (as per Jace11's suggestion):

Code:
from random import randint
group.speed = randint(5,9)
group.updateWaypointSpeed()
Which makes the group speed random between 5 and 9 knots. Obviously, all instances of the group will travel at the same random speed

You can use any of the functions described in the python documentation...

(edit to fix problem in example)

Last edited by mcoca; 05-03-07 at 06:31 PM.
mcoca is offline   Reply With Quote
Old 05-03-07, 05:58 PM   #2
Jace11
Seasoned Skipper
 
Join Date: Mar 2005
Location: UK
Posts: 683
Downloads: 104
Uploads: 1
Default

Just re-stating my gratitude for this. It will speed things up for the people who are editing the campaign layers.

Last edited by Jace11; 05-03-07 at 06:29 PM.
Jace11 is offline   Reply With Quote
Old 05-03-07, 06:09 PM   #3
akdavis
Samurai Navy
 
Join Date: Mar 2005
Location: Fort Worth, Texas
Posts: 597
Downloads: 0
Uploads: 0
Default

This is superb, especially the random speed functionality.
__________________
-AKD
akdavis is offline   Reply With Quote
Old 05-03-07, 06:30 PM   #4
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

What would be the code to randomly change speed on each way point i.e pt1 is 5, pt 2 is 8 etc ???
lurker_hlb3 is offline   Reply With Quote
Old 05-03-07, 06:50 PM   #5
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Thank you everybody for your support! Now, start using the thing so I can feel I haven't completely wasted my time :p

Quote:
Originally Posted by lurker_hlb3
What would be the code to randomly change speed on each way point i.e pt1 is 5, pt 2 is 8 etc ???
I'm writing from memory, but it would be something along these lines:

Code:
from random import randint
for waypoint in group.waypoints:
    waypoint.speed = randint(2,8)
Obviously, change the numbers to the ones you want. The spaces at the beginning of the third line are important, since python uses indentation to control what's inside the loop and what isn't.

BTW, if you want to get cute, there are functions to provide randomness along a probability curve, so most of the time ships will be around the middle of the range, with the occasional fast or slow one. Check the docs if you are interested.
mcoca is offline   Reply With Quote
Old 05-03-07, 06:58 PM   #6
lurker_hlb3
Admiral
 
Join Date: Apr 2005
Location: San Diego Calif
Posts: 2,290
Downloads: 187
Uploads: 12
Default

Quote:
Originally Posted by mcoca
Thank you everybody for your support! Now, start using the thing so I can feel I haven't completely wasted my time :p

Quote:
Originally Posted by lurker_hlb3
What would be the code to randomly change speed on each way point i.e pt1 is 5, pt 2 is 8 etc ???
I'm writing from memory, but it would be something along these lines:

Code:
from random import randint
for waypoint in group.waypoints:
    waypoint.speed = randint(2,8)
Obviously, change the numbers to the ones you want. The spaces at the beginning of the third line are important, since python uses indentation to control what's inside the loop and what isn't.

BTW, if you want to get cute, there are functions to provide randomness along a probability curve, so most of the time ships will be around the middle of the range, with the occasional fast or slow one. Check the docs if you are interested.

It worked perfectly, thanks very much
lurker_hlb3 is offline   Reply With Quote
Old 05-04-07, 09:12 AM   #7
Yanaran
Watch
 
Join Date: Apr 2007
Posts: 29
Downloads: 0
Uploads: 0
Default

Thanks for this awesome tool. Now I can finally make some changes myself!

I have a few simple questions though. I want to reduce traffic similar to your example script, but I also want to make convoys smaller early in the war and have less escorts. Is it enough to just reduce the spawnprobability for every unit in a convoy to say half? Like this for example,

if unit.type == UnitType.DESTROYER:
unit.spawnProbability *= 0.25
else:
unit.spawnProbability *= 0.5

Also, I'd like to remove all gunboats from the subhunter groups, and maybe replace them with some other ships like subchaser or minesweepers. Can I replace the "type" of ship or do I need to remove the gunboat unit altogether and then add a subhunter unit? I want to keep all the stats for the unit the same (crew, spawnprobability etc).
Yanaran is offline   Reply With Quote
Old 05-04-07, 09:44 AM   #8
akdavis
Samurai Navy
 
Join Date: Mar 2005
Location: Fort Worth, Texas
Posts: 597
Downloads: 0
Uploads: 0
Default

Best thing to do with gunboats would probably be to change their type so they aren't spawned as patrol vessels (or whatever type is drawn on for that group).
__________________
-AKD
akdavis is offline   Reply With Quote
Old 05-04-07, 09:52 AM   #9
U-Bones
Grey Wolf
 
Join Date: Mar 2005
Location: Treading Water
Posts: 847
Downloads: 56
Uploads: 0
Default

It would be nice to have both brown and blue water hunter/killer groups

Blue: DD/Subchaser/Minesweeper
Brown: Subchaser/Minesweeper/Gunboats

or similar.

Brown groups would also be common near smaller ports.
U-Bones is offline   Reply With Quote
Old 05-04-07, 10:15 AM   #10
mcoca
Loader
 
Join Date: Apr 2005
Location: Madrid, Spain
Posts: 86
Downloads: 0
Uploads: 0
Default

Quote:
Originally Posted by Yanaran
I have a few simple questions though. I want to reduce traffic similar to your example script, but I also want to make convoys smaller early in the war and have less escorts. Is it enough to just reduce the spawnprobability for every unit in a convoy to say half? Like this for example,

if unit.type == UnitType.DESTROYER:
unit.spawnProbability *= 0.25
else:
unit.spawnProbability *= 0.5
Yes, that should work... except that I'm not sure what happens if the lead unit in the group doesn't spawn? But the editor let's you enter such a group, so it's no big deal.

OTOH, you could remove half the entries using group.units.remove(unit) and some condition, but adding some kind of counter to how many there were and how many you removed.

Quote:
Also, I'd like to remove all gunboats from the subhunter groups, and maybe replace them with some other ships like subchaser or minesweepers. Can I replace the "type" of ship or do I need to remove the gunboat unit altogether and then add a subhunter unit? I want to keep all the stats for the unit the same (crew, spawnprobability etc).
The best solution, as tater suggested in another thread, would be to move the subhunter and the minesweeper to the "corvette" category by editing the roster files and changing the type=0 to type=1. Then, switch all the patrol craft in the campaign to corvettes:

Code:
if unit.type==UnitType.PATROL_CRAFT:
    unit.type=UnitType.CORVETTE
And if you want to add some gunboats around coastal areas, do so manually with editor. Unless you are a really enterprising programmer and can figure out a way to tell coastal patrols apart based on long/lat
mcoca is offline   Reply With Quote
Old 05-04-07, 11:23 AM   #11
Yanaran
Watch
 
Join Date: Apr 2007
Posts: 29
Downloads: 0
Uploads: 0
Default

Well that seems a bit more complicated than I thought, what I'm trying right now instead is sort of reverse what you did for destroyers... In every SubHunter group I check if it's a patrol craft and then set that units shipclass to subchaser. I think that should turn all gunboats into subchasers, which is good enough for me until I learn more.


Code:
if group.groupName.find("SubHunter") != -1:
    if group.groupName.find("Jap") != -1:
        # less subhunter groups
        group.spawnProbability *= 0.5
        for unit in group.units:
            if unit.type == UnitType.PATROL_CRAFT:
                unit.shipClass="SCSubchaser"
Yanaran 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:17 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.