News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

Water Supply Company (.bat file)

Started by Qayyum, March 11, 2025, 04:59:56 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Qayyum

Hello. I have recently finish my project, Water Supply Company. You simply adjust pump speed while weather changes. Here - the code below should be saved in .bat extension i.e. wsc.bat. Have fun playing!
@echo off
title Water Supply Company
:Menu
cls
@echo off
setlocal enabledelayedexpansion

set "file_path=wscweather.txt"

:: Count the number of lines in the file
for /f %%a in ('type "%file_path%" ^| find /c /v ""') do set "line_count=%%a"

:: Generate a random index and retrieve the corresponding name
set /a "random_index=!RANDOM! %% line_count"
set "count=0"

:: Read the file and set the winner
for /f "usebackq skip=%random_index% tokens=* delims=" %%a in ("%file_path%") do (
    if !count! equ 0 (
        set "random_name=%%a"
        echo The weather is: !random_name!
    )
    set /a "count+=1"
)

endlocal
echo Choose pump output.
echo 1) Slow
echo 2) Medium
echo 3) Speedy
echo 4) Exit
echo.
choice /C:1234 /M Choice?

if ERRORLEVEL 4 (
goto :End
)

if ERRORLEVEL 3 (
goto :Option3
)

if ERRORLEVEL 2 (
goto :Option2
)

if ERRORLEVEL 1 (
goto :Option1
)


:Option1
echo Pump is slow.


:::: Return to menu
timeout 2
goto :Menu


:Option2
echo Pump is at medium speed.


:::: Return to menu
timeout 2
goto :Menu


:Option3
echo Pump is at full speed.


:::: Return to menu
timeout 2
goto :Menu


:::: End of file. Pause and clean up
:End
echo.
echo Bye, bye!
echo.

pause

cls
For wscweather.txt:
Sunny
Raining
Cloudy


My content is Public Domain.

Simutrans - the open source Transport Tycoon Deluxe clone.