lundi 19 août 2019

Is it possible to make a randomly generated variable in batch?

I'm currently setting up a game in batch that will be able to randomly generate a world with events and structures, however I can only come up with setting each coordinate up.

This would be fine if I had a very small world, and this is what I have generated for the first 9 chunks for biome data, however I plan on making the game's world virtually infinite. What I want to do is have it so that if a player gets 11 tiles away from an ungenerated chunk, it will generate it.

The code I have currently manually generates the first 9 chunks without generating the variables themselves. The generation take in account the tiles around it so the biome data makes sense (There aren't any glaciers in the Sahara), and this tends to make the biomes similar in temperature. For reference, each chunk is 50x50 tiles.

This is the code that I have now:

rem 0x 0y
set /A biomenum0x0y = %RANDOM% * 16 / 32768 + 1
rem 0x 1y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenum0x1y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenum0x1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenum0x1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenum0x1y =  biomenum0x0y - 1
rem 1x 1y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenum1x1y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenum1x1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenum1x1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenum1x1y =  biomenum0x0y - 1
rem 1x 0y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenum1x0y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenum1x0y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenum1x0y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenum1x0y =  biomenum0x0y - 1
rem 1x -1y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenum1xneg1y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenum1xneg1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenum1xneg1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenum1xneg1y =  biomenum0x0y - 1
rem 0x -1y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenum0xneg1y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenum0xneg1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenum0xneg1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenum0xneg1y =  biomenum0x0y - 1
rem -1x -1y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenumneg1xneg1y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenumneg1xneg1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenumneg1xneg1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenumneg1xneg1y =  biomenum0x0y - 1
rem -1x 0y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenumneg1x0y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenumneg1x0y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenumneg1x0y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenumneg1x0y =  biomenum0x0y - 1
rem -1x 1y
set /A nextbiomenum = %RANDOM% * 4 / 32768 + 1
if /I "%nextbiomenum%" EQU "1" set /A biomenumneg1x1y =  biomenum0x0y + 1
if /I "%nextbiomenum%" EQU "2" set /A biomenumneg1x1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "3" set /A biomenumneg1x1y =  biomenum0x0y + 0
if /I "%nextbiomenum%" EQU "4" set /A biomenumneg1x1y =  biomenum0x0y - 1
echo %biomenumneg1xneg1y% is the biome for -1,-1
echo %biomenumneg1x0y% is the biome for -1, 0
echo %biomenumneg1x1y% is the biome for -1, 1
echo %biomenum0xneg1y% is the biome for 0, -1
echo %biomenum0x0y% is the biome for 0, 0 -the starting chunk-
echo %biomenum0x1y% is the biome for 0, 1
echo %biomenum1xneg1y% is the biome for 1, -1
echo %biomenum1x0y% is the biome for 1, 0
echo %biomenum1x1y% is the biome for 1, 1

The echo %biomenumneg1xneg1y% is the biome for -1,-1 part isn't going to be in the final game, it's just a debug thing I put there so I could make sure the numbers are working fine.

I want to be able to randomly generate variables, however as far as I'm aware you cannot put a variable inside of the variable name itself. I then plan on automatically assigning coordinates to chunks based on more variables inside variable names, maybe something like dividing the coordinates by 50 and rounding to the nearest 1 to make each variable assigned to a chunk.




Aucun commentaire:

Enregistrer un commentaire