Quick & Cheap Python Script: Random Skirmish beta .0001

Quick & Cheap Python Script: Random Skirmish beta .0001

Discuss everything related to running Spring on your chosen distribution of Linux.

Moderator: Moderators

Post Reply
User avatar
Slamoid
Posts: 237
Joined: 25 Jan 2005, 19:23

Quick & Cheap Python Script: Random Skirmish beta .0001

Post by Slamoid »

This script was made for people who just want to play single player. Just paste this into a text file, make sure that a start script is in the same directory, and run it with Python. Your runline should look somthing like:

Code: Select all

python SpringRS.py; spring script.txt
 
This will alter the script file to randomize:
  • Map
    Sides
    Colors
    AI Difficulty
You'll want to change some variables, but I marked what ones, so it's pretty editable.

Please keep in mind that this is VERY beta, and is probably not for total noobs.

Code: Select all

#~Change this to the script file to alter
scri= './script.txt'
#~Change this to where your Map files are at
mapdir= '/shared/Games/SpringData/maps'



#This imports the needed libs
import random
import os
#Open and Read the script
def ReadScript(sloc):
 fil=open(sloc,'r')
 return fil.readlines()
 fil.close()
#Open the Script File, and copy it to the internal array.
filar=ReadScript(scri)
map = os.listdir(mapdir)
map = map[random.randint(0,len(map))]
if map=="paths":
 map = map[random.randint(0,len(map))]
map = map.replace('.sd7','.smf')
map = map.replace('.sdz','.smf')
rmap='Mapname='+map
rmap=rmap+';\n' #Bugfix!
#Write the new map
#Also, randomize the sides! (New Feature)
#Just for kicks, randomize the colors too!
i=0
while i<len(filar):
 line=filar[i]
 if 'Mapname=' in line:
  print 'Changing mapname on line ' + str(i)
  filar[i]=rmap
  print filar[i]
 if 'Side=' in line:
  print 'Changing a side on line ' + str(i)
  filar[i]='Side=Arm;\n'
  if random.randint(0,1)==1:
   filar[i]='Side=Core;\n'
 if 'RgbColor=' in line:
  print 'Changing a color on line ' + str(i)
  rgbl = 'RgbColor='
  rgbl=rgbl+str(float(random.randint(0,9))/10)
  rgbl=rgbl+' '
  rgbl=rgbl+str(float(random.randint(0,9))/10)
  rgbl=rgbl+' '
  rgbl=rgbl+str(float(random.randint(0,9))/10)
  rgbl=rgbl+';\n'
  filar[i]=rgbl
  print filar[i]
 if 'Handicap=' in line:
  print 'Changing Handicap on line ' + str(i)
  filar[i]='Handicap='+str(random.randint(5,55))+';\n'
  print filar[i]
 i=i+1
fil=open('script.txt','w')
fil.writelines(filar)
fil.close()
And here's the start script that I've been using. Make sure you put this in the same directory as the .py script.

Code: Select all

[GAME]
{
Mapname=TornIslands_V2.smf;
StartMetal=2000;
StartEnergy=2000;
MaxUnits=5000;
GameType=xtape.sd7;
GameMode=0;
StartPosType=1;
MyPlayerNum=0;
NumPlayers=1;
NumTeams=2;
NumAllyTeams=2;
HostIP=localhost;
HostPort=8452;       // usually 8452
[PLAYER0]
{
name=Flabbergaster;
Spectator=0;
team=0;
}    

[TEAM0]
{
TeamLeader=0;
RgbColor=0.6 0.2 0.5;
AllyTeam=0;
Side=Arm;
}
[TEAM1]
{
TeamLeader=0;
RgbColor=0.4 0.1 0.6;
Handicap=42;
AllyTeam=1;
Side=Core;
AiDLL=/shared/Games/SpringData/AI/Bot-libs/QAI-2.45.so;
}
[ALLYTEAM0]
{
NumAllies=0;
}
[ALLYTEAM1]
{
NumAllies=0;
}
}   

Please keep in mind that this will eventually be put into a single-player frontend in the future. Also, please feel free to post suggestions. Enjoy!
Post Reply

Return to “Linux”