Huge Project.....

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Huge Project.....

#1 Post by pditty8811 » 20 Mar 2013 02:58

I am looking to finish a huge project. I will summarize what I would like to do then I will list it in order in detail.

There will be SIX variables, and each loop they will be unique.
They are:

1. Mark name
2. Longitude
3. Latitude
4. Ship Class
5. Date
6. Ship Name


Summary of what we will be doing:

1. Search Marks.txt for Mark names (Variable 1)
2. Search .map file for Mark name (Variable 1) Once mark name is found take the coordinates that are there Longitude and Latitude (Variables 2 and 3)
3. Search .clg and Log_*.cfg files for "Ship sunk!" text. Following this text will be the Ship Class (Variable 4) on the same line, and the date two lines below this.
4. Open perl script with perl via batch command, called "PosTimeFilter.pl". Then enter Variables 5, 2 and 3 (in that order) into the script via commands.
5. The perl script will then output a file called "PosTime_Campaign_SCR.mis". This file will then be searched for the Ship Class (Variable 4). If the Ship Class is found in that file I'd like it to take the Ship Name (Variable 6), which can be found one line above the Ship Class.
6. I would then like it to find the Ship Name, the exact matching line, in "Campaign_SCR2.mis.tmp".
7. Once the Ship Name is found it would then replace that line (Name= line) and the four lines below it with:

Code: Select all

Name=ShipDummy
Class=ShipDummy
Type=0
Origin=Environmental
Side=0

8. I'd then like to have it loop where it takes the next Mark name, on the next line of Marks.txt as Variable 1, and then finds that mark in .map file. It would then react on the second instance of "Ship sunk!" entry that it found in .clg and Log_*.cfg files. And so on. The third Mark name would pair with the third instance of "Ship sunk!" found and so on.






Detailed Explanation, Step-by-Step

So here goes. I will run through the process with you, but I'd like it to be a loop that does the same process over and over again for each mark.

1.
I'd like to search Marks.txt, which will be in the same folder as the batch file we are creating, for entries which will be each on a line.

The entries will be for example :

Code: Select all

Mark 1
Mark 3
Mark 4
etc...


I'd like to take the first entry as Variable 1. "Mark 1"

2. Then I'd like to search in *.map files in directory "C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR2". It would be searching forVariable 1, which will always be found at the end of a line. (for example "Pt0=14497903.00,-813490.00,0.00,Mark 1"). I'd then like to grab the coordinates that are just before it (these are Longitude and Latitude). I'm not concerned with the third number (0.00). The Longitude here is "14497903.00" (Variable 2) and it's in meters. I'm saying this because we will have to convert the coordinates to km for the perl script, and the perl script only takes whole numbers too, so no decimal places. Should be easy though because its just subtracting 3 decimal places. And we have the Latitude "-813490" (Variable 3).

An example of what the .map files will look like:

Code: Select all

[Mark]
PointsNb=6
Pt0=14497903.00,-813490.00,0.00,Mark 1
Pt1=14498483.00,-813310.00,0.00,Mark 2
Pt2=14498843.00,-813650.00,0.00,Mark 3
Pt3=14499233.00,-814280.00,0.00,Mark 4
Pt4=14498483.00,-814480.00,0.00,Mark 5
Pt5=14498293.00,-814970.00,0.00,Mark 6

[Ruler]
PointsNb=0

[Range]
PointsNb=0

[Angle]
PointsNb=0

[Waypoint]
PointsNb=1
Pt0=14498362.99,-813982.55,-2.53




3. Now, we will grab Variables 4 and 5 from the .log and Log*.cfg files, Ship Class and Date. Again we will be searching in directory "C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR2" for these variables. We will be looking for entry "Ship sunk!". Looking for the first instance of "Ship sunk!" only. The Ship Class (Variable 4) lies soon after those words on the same line (example "EntryText=Ship sunk!|Grid CJ 73|BISMARCK BATTLESHIP, 50950 tons") In the example "BISMARCK BATTLESHIP" is the Ship Class. Notice how it follows a | grid coordinates another | and then the Ship Class. We will be grabbing the Ship Class.

We will also be grabbing Variable 5 here too, the Date. The date is in the same format as what we will put into the perl script, so no changing date formats. The Date lies two lines below the Ship sunk! and Ship Class line.

Exmaple

Code: Select all

EntryText=Ship sunk!|Grid CJ 73|BISMARCK BATTLESHIP, 50950 tons
EntryTitle=September 15, 1941, 16:55
Date=19410915


We need to grab what is after "Date=". "19410915" That is Variable 5.

4. Now we will open the perl script. This can be done with the following code:

Code: Select all

cd "E:\Program Files (x86)\Ubisoft\SilentHunterIII\Dynamic Campaign\Perl"

perl PosTimeFilter.pl


However, I do not know how to tell a batch file to enter commands in the cmd prompt when the script is running.

The commands to be entered are follows:

s (press letter "s")
"Press ENTER Button"
Variable 5 minus 1 day. So if it's 19410915 as the example above, I'd like it to be "19410914". It's in format YYYYMMDD.
"Press ENTER Button"
Variable 5 plus 1 day. So if it's 19410915 as the example above, I'd like it to be "19410916". It's in format YYYYMMDD.
"Press ENTER Button"
Variable 2 in km, plus 2. So if its 14497903 as the example I'd like it to be changed to km (14497) then add 2km. So "14499".
"Press ENTER Button"Variable 2 in km, minus 2. So if its 14497903 as the example I'd like it to be changed to km (14497) then minus 2km. So "14495".
"Press ENTER Button"
Variable 3 in km, plus 2. So if its -813490 as the example I'd like it to be changed to km (-813) then add 2km. So "-811".
"Press ENTER Button"
Variable 3 in km, minus 2. So if its -813490 as the example I'd like it to be changed to km (-813) then minus 2km. So "-815".
"Press ENTER Button"


Then it will load. This may take about 15 seconds. After it has loaded, all we have to do is:

y (press letter "y")
"Press ENTER Button"


Perl script then exits.

Basically what we are inputing are are a date range, longitude range and latitude range to pinpoint exactly what ships within the campaign script was at that place and time when the ship was sunk.



5.
The perl script will then will create an output file called "PosTime_Campaign_SCR.mis". This file will be in same directory as this batch file we are creating. I'd then like to search that file for Variable 4, the Ship Class. Our ship class in the example was "BISMARCK BATTLESHIP". Within "PosTime_Campaign_SCR.mis" it will appear as "Class=BISMARCK BATTLESHIP", all on one line.
It is likely to find that ship class within the file. If it is found I would then like to pull Variable 6 from that file, Ship Name. The Ship Name will appear on the line just above "Class=BISMARCK BATTLESHIP", the Ship Class. Example:

Code: Select all

Name=Bismarck #24
Class=BISMARCK BATTLESHIP


In this example I'd like "Name=Bismarck #24" to be Variable 6. Notice it is on the line above the Ship Class.


6. I would then like to find Variable 6 in "Campaign_SCR2.mis.tmp" file. This file will be in the same directory as the batch file we are creating.

7. If Variable 6 is found, "Name=Bismarck #24" I'd like that line and the four lines below it to be replaced with (NOT the already existing lines to be pushed down) with:

Code: Select all

Name=ShipDummy
Class=ShipDummy
Type=0
Origin=Environmental
Side=0



8. I'd then like to have it loop where it takes the next Mark name, on the next line of Marks.txt as Variable 1, and then finds that mark in .map file. It would then react on the second instance of "Ship sunk!" entry that it found in .clg and Log_*.cfg files. And so on. The third Mark name would pair with the third instance of "Ship sunk!" found and so on.



Whomever would like to take on this beast, or help me in taking it on, I'd be much appreciated.

In essence here what is trying to be created is a dynamic campaign for a game called Silent Hunter 3. Basically what we have is the player will mark on the navigation map when a ship is sunk, putting the name of the mark in Marks.txt. The coordinates of this is then found in the .map file and then it is paired with the entry of the sunken ship that the game creates in the .clg and Log_*.cfg files. Using a perl script created by another modder for editing the game's campaign script, the coordinates and date taken from the above are then plugged into the perl script. It will then output a file, that output file is a date range and coordinate range section of the campaign script/map. That output file is then search for the ship class. The Ship name of that ship class is then found, which is often a uniqu ship name. That ship name is then found within the main campaign script of the game and changed so the ship does not appear in game any longer. Dynamic Campaign!

Thank you.

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Huge Project.....

#2 Post by pditty8811 » 20 Mar 2013 18:09

This is what I have so far. I'm having an issue telling the for loop to look on the same text line that the findstr command found the string, so I am using the skip= command right now. But here is what I got:

Code: Select all

set var1=!var1!%%A

findstr /e "!var1!" "*.map"

if not errorlevel 1 (
 
for /f "skip=3 tokens=2 delims==,." %%B in (test4.map) do (
set var2=!var2!%%B

set /a linecount+=1
if !linecount! GEQ %maxlines% GOTO part2
)
:part2
for /f "skip=3 tokens=4 delims==,." %%C in (test4.map) do (
set var3=!var3!%%C
if !linecount! GEQ %maxlines% GOTO exitloop
)
)


)
:exitloop

set /a var2/=1000
set /a var3/=1000





findstr /e "Ship sunk!" "*.clg" "Log_*.cfg"

if not errorlevel 1 (



How do I execute the for loop to search the same line that the findstr command found the string?

Post Reply