Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- encoding:Latin-1 -*-
- #THIS PROGRAM CREATES RANDOM SCENARIOS FOR ROTK11
- #RandOTK11 v1.05
- #
- #
- # IMPORTING WIDGETS AND DEFINING VARIABLES
- #
- import os
- from random import *
- from tkinter import *
- from tkinter import messagebox
- from tkinter.filedialog import *
- chk = b'KOEI%SAN11'
- authorized_filesizes = [167559, 169822, 179109]
- helptext = "RandOTK11 v1.05\n\n Information : This program randomizes Romance of the Three Kingdoms XI Scenario Files (.S11 extension) and has been developed in Python by Zetta on the forums of http://the-scholars.com/"
- #
- # DEFINE FUNCTIONS
- #
- #
- # DEFINE HELP / INFO FUNCTION
- #
- def info():
- global helptext
- messagebox.showinfo("Help", helptext)
- #
- # DEFINE EXIT FUNCTION
- #
- def exitrandotk():
- global window
- try:
- Scen.close()
- except:
- pass
- window.destroy()
- #
- # DEFINE OPEN FILE FUNCTION
- #
- def openSCEN():
- global Scen,File,Filesize
- File = askopenfilename(defaultextension = ".S11", filetypes = [("S11","*.S11")])
- try:
- Scen = open(File, "rb+")
- Scen.seek(8,0)
- f = Scen.read(10)
- Filesize = os.path.getsize(File)
- if chk == f and Filesize in authorized_filesizes:
- randbtn.config(state = ACTIVE)
- if chk != f or Filesize not in authorized_filesizes:
- print("ERROR: chosen file is not a ROTK11 scenario file")
- Scen.close()
- randbtn.config(state = DISABLED)
- except:
- print("No File selected")
- randbtn.config(state = DISABLED)
- #
- #
- # DEFINE RANDOMIZE FUNCTION
- #
- #
- def Randomize():
- global a,b,c,d,e,f,x,y,IA,equi,res,HistVar,rdoff,fnum,LifeVar,CityVar,AllyVar,Filesize
- randbtn.config(state = DISABLED)
- leaders = [9, 16, 17, 18, 20, 50, 65, 91, 101, 105, 109, 120, 129, 149, 160, 180, 182, 184, 190, 225, 263, 288, 328, 343, 347, 349, 350, 358, 362, 365, 367, 368, 370, 383, 415, 431, 442, 465, 484, 493, 515, 517, 568, 598, 614, 618, 624, 629, 631, 632, 635, 636, 660]
- colors = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41]
- cities = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41]
- nghb = [[1], [0,2,3], [1,3,5], [2,4], [3,6,7,11], [2,6], [4,5,11,12], [4,8,9], [7,9], [7,8,10,11,12], [9,14,25], [4,6,7,9,12], [6,9,11,13,15,16], [12,14,16,28], [10,13,28], [12,16,17], [13,15,17,18,28], [15,16,19,36], [16,29,36], [17,20,21], [17,19,21,36], [19,20], [23,25], [22,24], [23], [10,22,26,27], [25,27,30,31], [25,26,28,30], [13,14,16,27,29], [18,28,30,35], [26,27,29,31,32,35], [26,30,32,33], [30,31,34], [31,34], [32,33], [29,30,38], [18,20,37], [36,39], [35,39,40], [37,38], [38,41], [40]]
- gates = [[10], [], [], [], [11], [0,12], [13], [14,15], [16,17], [], [18], [19], [20], [], [], [1,21,22], [], [23,2,3,4], [25], [], [], [], [26,27], [28], [29], [30], [31,32,33,34], [35], [36], [37], [38,39,40], [41], [42,43], [], [], [44], [5], [6,7], [], [8,9], [], []]
- forces = []
- #
- # PREPARING A BLANK SCENARIO BY DEFAULT
- #
- # SCENARIO NAME AND DESCRIPTION
- #
- if Filesize ==179109:
- sname = b'Random\x20Scenario'
- Scen.seek(95,0)
- Scen.write(sname)
- Scen.write(bytes(5))
- Scen.seek(121,0)
- Scen.write(bytes(450))
- #
- # BLANK MAP PREVIEW
- #
- if Filesize==179109:
- Scen.seek(722,0)
- if Filesize==169822:
- Scen.seek(475,0)
- if Filesize==167559:
- Scen.seek(418,0)
- Scen.write(42*bytes([255]))
- #
- # BLANK FORCES DESCRIPTION
- #
- if Filesize==179109:
- x = 0
- while x<42:
- Scen.seek(932+x*607,0)
- Scen.write(bytes([0,20]))
- Scen.write(bytes(605))
- x+=1
- #
- # OFFICERS BLANK
- #
- x = 0
- while x<670:
- if Filesize==179109:
- Scen.seek(28098+x*152, 0)
- if Filesize==169822:
- Scen.seek(17855+x*152, 0)
- if Filesize==167559:
- Scen.seek(15404+x*152, 0)
- Scen.write(bytes([255]))
- a = [randrange(0,42),0]
- Scen.write(bytes(a))
- Scen.write(bytes(a))
- y = choice([4,7,7,7])
- Scen.write(bytes([y]))
- Scen.write(b"\x50")
- if Filesize==179109:
- Scen.seek(28107+x*152, 0)
- if Filesize==169822:
- Scen.seek(17864+x*152, 0)
- if Filesize==167559:
- Scen.seek(15413+x*152, 0)
- Scen.write(bytes(3))
- x+=1
- #
- # FORCE SLOTS BLANK
- #
- y = 0
- while y<42:
- L = [255,255,255,255]
- L.extend([50]*y)
- L.extend([100])
- L.extend((41-y)*[50])
- if Filesize==179109:
- Scen.seek(160603+y*68, 0)
- if Filesize==169822:
- Scen.seek(152660+y*68, 0)
- if Filesize==167559:
- Scen.seek(150209+y*72, 0)
- Scen.write(bytes(L))
- Scen.write(bytes(5))
- Scen.write(bytes([9, 255, y, 255, 255]))
- Scen.write(bytes(12))
- y+=1
- #
- # DISTRICTS BLANK
- #
- y = 0
- while y<42:
- L = [255,00,255,255,255,255,255,255]
- if Filesize==179109:
- Scen.seek(163799+y*8, 0)
- if Filesize==169822:
- Scen.seek(155856+y*8, 0)
- if Filesize==167559:
- Scen.seek(153593+y*8, 0)
- Scen.write(bytes(L))
- y+=1
- #
- # CITIES BLANK
- #
- y = 42
- while y:
- y-=1
- if Filesize==179109:
- Scen.seek(164175+y*81, 0)
- if Filesize==169822:
- Scen.seek(156232+y*81, 0)
- if Filesize==167559:
- Scen.seek(153969+y*81, 0)
- Scen.write(b"\xff")
- #
- if Filesize==179109:
- Scen.seek(164179+y*81, 0)
- if Filesize==169822:
- Scen.seek(156236+y*81, 0)
- if Filesize==167559:
- Scen.seek(153973+y*81, 0)
- Scen.write(bytes(61))
- #
- if Filesize==179109:
- Scen.seek(164248+y*81, 0)
- if Filesize==169822:
- Scen.seek(156305+y*81, 0)
- if Filesize==167559:
- Scen.seek(154042+y*81, 0)
- Scen.write(b"\x00"+b"\x32")
- #
- #GATES AND PORTS BLANK
- #
- y = 45
- while y:
- y-=1
- if Filesize==179109:
- Scen.seek(167577+y*64, 0)
- if Filesize==169822:
- Scen.seek(159634+y*64, 0)
- if Filesize==167559:
- Scen.seek(157371+y*64, 0)
- Scen.write(b"\xff")
- Scen.write(bytes(61))
- print("Scenario has been made blank for preparation.")
- #
- #
- # THIS IS THE STARTING PART OF THE RANDOMIZER
- # SETUP STARTING DATE SELECTION
- #
- #
- try:
- sdate = int(SdateEntry.get())
- if sdate<0 or sdate >300:
- sdate = randrange(160,300)
- except:
- sdate = randrange(160,300)
- w = [sdate%256, sdate//256, randrange(0,13)]
- Scen.seek(91, 0)
- Scen.write(bytes(w))
- if Filesize==179109:
- Scen.seek(26427, 0)
- if Filesize==169822:
- Scen.seek(16184, 0)
- if Filesize==167559:
- Scen.seek(13733, 0)
- Scen.write(bytes(w))
- #
- # OFFICERS UPDATE AND CREATION OF A LIST OF FREE OFFICERS
- #
- x = 0
- offi = []
- while x<670:
- if Filesize==179109:
- Scen.seek(28059+x*152, 0)
- if Filesize==169822:
- Scen.seek(17816+x*152, 0)
- if Filesize==167559:
- Scen.seek(15365+x*152, 0)
- avail = ord(Scen.read(1)) + 256*ord(Scen.read(1))
- birth = ord(Scen.read(1)) + 256*ord(Scen.read(1))
- #
- if LifeVar.get()==1:
- deathd = birth + randrange(30,100)
- Scen.write(bytes([deathd%256, deathd//256]))
- if Filesize==179109:
- Scen.seek(28059+x*152, 0)
- if Filesize==169822:
- Scen.seek(17816+x*152, 0)
- if Filesize==167559:
- Scen.seek(15365+x*152, 0)
- avail = birth + randrange(15,31)
- Scen.write(bytes([avail%256, avail//256]))
- if LifeVar.get()==0:
- deathd = ord(Scen.read(1)) + 256*ord(Scen.read(1))
- #
- if Filesize==179109:
- Scen.seek(28103+x*152, 0)
- if Filesize==169822:
- Scen.seek(17860+x*152, 0)
- if Filesize==167559:
- Scen.seek(15409+x*152, 0)
- if sdate > deathd:
- Scen.write(b"\x08")
- if x in leaders:
- leaders.remove(x)
- if sdate < avail:
- Scen.write(b"\x06")
- if x in leaders:
- leaders.remove(x)
- if avail<=sdate<deathd:
- offi.append(x)
- x+=1
- totaloff = len(offi)
- #
- # EMPEROR UPDATE
- #
- if sdate>189:
- if Filesize==179109:
- Scen.seek(26431,0)
- Scen.write(bytes([190,2]))
- Scen.seek(134503, 0)
- Scen.write(bytes([8]))
- Scen.seek(134503+152, 0)
- Scen.write(bytes([8]))
- Scen.seek(134503+2*152, 0)
- Scen.write(bytes([255]))
- if Filesize==169822:
- Scen.seek(16188,0)
- Scen.write(bytes([190,2]))
- Scen.seek(124260, 0)
- Scen.write(bytes([8]))
- Scen.seek(124260+152, 0)
- Scen.write(bytes([8]))
- Scen.seek(124260+2*152, 0)
- Scen.write(bytes([255]))
- if Filesize==167559:
- Scen.seek(13737,0)
- Scen.write(bytes([190,2]))
- Scen.seek(121809, 0)
- Scen.write(bytes([8]))
- Scen.seek(121809+152, 0)
- Scen.write(bytes([8]))
- Scen.seek(121809+2*152, 0)
- Scen.write(bytes([255]))
- if sdate<=189:
- if Filesize==179109:
- Scen.seek(26431,0)
- Scen.write(bytes([188,2]))
- Scen.seek(134503, 0)
- Scen.write(bytes([255]))
- Scen.seek(134503+152, 0)
- Scen.write(bytes([8]))
- Scen.seek(134503+2*152, 0)
- Scen.write(bytes([255]))
- if Filesize==169822:
- Scen.seek(16188,0)
- Scen.write(bytes([188,2]))
- Scen.seek(124260, 0)
- Scen.write(bytes([255]))
- Scen.seek(124260+152, 0)
- Scen.write(bytes([8]))
- Scen.seek(124260+2*152, 0)
- Scen.write(bytes([255]))
- if Filesize==167559:
- Scen.seek(13737,0)
- Scen.write(bytes([188,2]))
- Scen.seek(121809, 0)
- Scen.write(bytes([255]))
- Scen.seek(121809+152, 0)
- Scen.write(bytes([8]))
- Scen.seek(121809+2*152, 0)
- Scen.write(bytes([255]))
- #
- # OFFICER RANDOMIZER
- #
- if rdoff.get()==1:
- x = 0
- while x<670:
- if Filesize==179109:
- Scen.seek(28110+x*152,0)
- if Filesize==169822:
- Scen.seek(17867+x*152,0)
- if Filesize==167559:
- Scen.seek(15416+x*152,0)
- f1 = randrange(1,6)
- # defining 4 types of random officers : 1 is hero, 2 is strategist, 3 is general, 4 is standard and 5 is random
- if f1==1:
- f = [randrange(1,4), randrange(1,4), randrange(1,4),randrange(1,4),randrange(0,4), randrange(1,4), randrange(65,101), randrange(65,101), randrange(65,96), randrange(65,96), randrange(65,96)]
- if f1==2:
- f = [randrange(0,3), randrange(0,3), randrange(1,4),randrange(0,4),randrange(1,4), randrange(1,4), randrange(50,81), randrange(50,81), randrange(75,101), randrange(75,101), randrange(75,101)]
- if f1==3:
- f = [randrange(0,4), randrange(0,4), randrange(0,4),randrange(0,4),randrange(0,4), randrange(0,4), randrange(80,98), randrange(80,97), randrange(40,81), randrange(40,81), randrange(80,94)]
- if f1==4:
- f = [randrange(0,3), randrange(0,3), randrange(0,3),randrange(0,3),randrange(0,3), randrange(0,3), randrange(20,61), randrange(20,61), randrange(20,61), randrange(20,61), randrange(20,61)]
- if f1==5:
- f = [randrange(0,4), randrange(0,4), randrange(0,4),randrange(0,4),randrange(0,4), randrange(0,4), randrange(2,80), randrange(1,80), randrange(3,80), randrange(1,80), randrange(5,80)]
- Scen.write(bytes(f))
- if Filesize==179109:
- Scen.seek(28127+x*152,0)
- if Filesize==169822:
- Scen.seek(17884+x*152,0)
- if Filesize==167559:
- Scen.seek(15433+x*152,0)
- f2 = 255
- if f[7]>=75:
- f2 = choice([255, randrange(10,53)])
- if f[8]>=70:
- f2 = choice([255, randrange(53,79)])
- if f[9]>=60 or f[10]>60:
- f2 = choice([255, randrange(79,100)])
- if f[6]>=70:
- f2 = choice([255, randrange(0,10)])
- if f[6]>=85 and f[0]==3:
- f2 = choice([255,34,42])
- if f[6]>=85 and f[1]==3:
- f2 = choice([255,35,43])
- if f[6]>=85 and f[2]==3:
- f2 = choice([255,36,44])
- if f[6]>=85 and f[3]==3:
- f2 = choice([255,25,37,45,49])
- if f[6]>=85 and f[3]==5:
- f2 = choice([255,38,47])
- Scen.write(bytes([f2]))
- x+=1
- #
- # SETUP FOR NUMBER OF FORCES
- #
- try:
- fnum = int(FnumEntry.get())
- except:
- fnum = randrange(2,43)
- if fnum>42 or fnum<2:
- fnum = randrange(2,43)
- print("There is " + str(len(offi)) + " officers available at year " + str(sdate) + " in this scenario.")
- #
- # REMOVE LEADERS FROM OFFICERS LIST
- #
- if HistVar.get()==1:
- for n in leaders:
- try:
- offi.remove(n)
- except:
- print(" \n ERROR : Could not remove officer from list \n")
- #
- # REMOVE FIXED NUMBER OF FREE CITIES
- #
- try:
- freecities = int(FcityEntry.get())
- if freecities>40 or freecities+fnum>42:
- freecities = 42 - fnum
- except:
- if fnum<41:
- freecities = randrange(0,41-fnum)
- if fnum==41:
- freecities = 0
- while freecities>0:
- cities.remove(choice(cities))
- freecities-=1
- avcity = len(cities)
- #
- # CODE FOR CREATION OF EACH RANDOM FORCE
- #
- # NOTE : b is force number being created, a is leader, d is capital and c is force color
- # e is list of owned cities and f and n are integers for various uses
- #
- #
- # CHOOSE A RULER FROM HISTORICAL OR OFFICERS LIST
- #
- leaderslist = []
- b=0
- while b<fnum and offi and len(cities):
- if HistVar.get()!=1 or not len(leaders):
- a = offi[randrange(0,len(offi))]
- offi.remove(a)
- if HistVar.get()==1 and len(leaders):
- a = leaders[randrange(0,len(leaders))]
- leaders.remove(a)
- leaderslist.append(a)
- #
- # MODIFY LEADER ATTRIBUTES
- #
- if Filesize==179109:
- Scen.seek(28098+a*152, 0)
- if Filesize==169822:
- Scen.seek(17855+a*152, 0)
- if Filesize==167559:
- Scen.seek(15404+a*152, 0)
- Scen.write(bytes([b]))
- e = []
- d = choice(cities)
- e.append(d)
- cities.remove(d)
- Scen.write(bytes([d]))
- Scen.write(bytes(1))
- Scen.write(bytes([d]))
- Scen.write(bytes(2))
- if Filesize==179109:
- Scen.seek(28107+a*152, 0)
- if Filesize==169822:
- Scen.seek(17864+a*152, 0)
- if Filesize==167559:
- Scen.seek(15413+a*152, 0)
- Scen.write(bytes([100]))
- #
- # CREATE FORCE
- #
- c = colors[randrange(0,len(colors))]
- forces.append(c)
- colors.remove(c)
- if Filesize==179109:
- Scen.seek(160603+c*68, 0)
- if Filesize==169822:
- Scen.seek(152660+c*68, 0)
- if Filesize==167559:
- Scen.seek(150209+c*72, 0)
- Scen.write(bytes([a%256]))
- Scen.write(bytes([a//256]))
- #
- # FORCE IA BEHAVIOR
- #
- if Filesize==179109:
- Scen.seek(160657+68*c,0)
- if Filesize==169822:
- Scen.seek(152714+68*c,0)
- if Filesize==167559:
- Scen.seek(150263+72*c,0)
- f = 0
- if IA.get()==1:
- f = 0
- if IA.get()==2:
- f = randrange(1,3)
- if IA.get()==3:
- f = randrange(0,6)
- Scen.write(bytes([f]))
- if f==1:
- Scen.write(bytes([randrange(0,6)]))
- if f==2:
- Scen.write(bytes([randrange(0,12)]))
- if f==0 or f==3 or f==4 or f==5:
- Scen.write(bytes([255]))
- #
- # CREATE FORCE DISTRICT
- #
- if Filesize==179109:
- Scen.seek(163799+b*8, 0)
- if Filesize==169822:
- Scen.seek(155856+b*8, 0)
- if Filesize==167559:
- Scen.seek(153593+b*8, 0)
- Scen.write(bytes([c]))
- Scen.write(bytes([1]))
- Scen.write(bytes([a%256]))
- Scen.write(bytes([a//256]))
- obk = choice([1,2])
- if obk ==1:
- Scen.write(bytes([1]))
- Scen.write(bytes([randrange(0,6)]))
- if obk ==2:
- Scen.write(bytes([2]))
- Scen.write(bytes([randrange(0,12)]))
- #
- # CITY ASSIGNMENT
- #
- if Filesize==179109:
- Scen.seek(164175+d*81, 0)
- if Filesize==169822:
- Scen.seek(156232+d*81, 0)
- if Filesize==167559:
- Scen.seek(153969+d*81, 0)
- Scen.write(bytes([b]))
- if equi.get()==4:
- equi.set(randrange(1,4))
- if equi.get()==1:
- f = int(len(cities)/fnum)
- if equi.get()==2:
- try:
- f = randrange(0,len(cities)-fnum+b)
- except:
- f = 0
- if equi.get()==3:
- f = 0
- while f>0:
- if CityVar.get()==1:
- for q in e:
- for r in nghb[q]:
- if r in cities and f>0:
- e.append(r)
- cities.remove(r)
- f-=1
- else:
- f-=1
- if CityVar.get()==0:
- try:
- r = choice(cities)
- e.append(r)
- cities.remove(r)
- except:
- print("Error : could not distribute more cities in non neighbour cities setup")
- f-=1
- #
- # EQUIP CITY TROOPS GOLD AND FOOD
- #
- for n in e:
- if Filesize==179109:
- Scen.seek(164175+n*81, 0)
- if Filesize==169822:
- Scen.seek(156232+n*81, 0)
- if Filesize==167559:
- Scen.seek(153969+n*81, 0)
- Scen.write(bytes([b]))
- #
- if Filesize==179109:
- Scen.seek(164180+n*81, 0)
- if Filesize==169822:
- Scen.seek(156237+n*81, 0)
- if Filesize==167559:
- Scen.seek(153974+n*81, 0)
- f = 500*randrange(30,91)
- Scen.write(bytes([f%256]))
- Scen.write(bytes([f//256]))
- #
- if Filesize==179109:
- Scen.seek(164184+n*81, 0)
- if Filesize==169822:
- Scen.seek(156241+n*81, 0)
- if Filesize==167559:
- Scen.seek(153978+n*81, 0)
- f = 500*randrange(4,15)
- Scen.write(bytes([f%256]))
- Scen.write(bytes([f//256]))
- #
- if Filesize==179109:
- Scen.seek(164188+n*81, 0)
- if Filesize==169822:
- Scen.seek(156245+n*81, 0)
- if Filesize==167559:
- Scen.seek(153982+n*81, 0)
- f = 1000*randrange(30,66)
- Scen.write(bytes([f%256]))
- Scen.write(bytes([f//256]))
- #
- # EQUIP CITY WEAPONS
- #
- if Filesize==179109:
- Scen.seek(164196+n*81, 0)
- if Filesize==169822:
- Scen.seek(156253+n*81, 0)
- if Filesize==167559:
- Scen.seek(153990+n*81, 0)
- f = 1000*randrange(0,6)
- Scen.write(bytes([f%256]))
- Scen.write(bytes([f//256]))
- #
- if Filesize==179109:
- Scen.seek(164200+n*81, 0)
- if Filesize==169822:
- Scen.seek(156257+n*81, 0)
- if Filesize==167559:
- Scen.seek(153994+n*81, 0)
- f = 1000*randrange(0,6)
- Scen.write(bytes([f%256]))
- Scen.write(bytes([f//256]))
- #
- if Filesize==179109:
- Scen.seek(164204+n*81, 0)
- if Filesize==169822:
- Scen.seek(156261+n*81, 0)
- if Filesize==167559:
- Scen.seek(153998+n*81, 0)
- f = 1000*randrange(0,6)
- Scen.write(bytes([f%256]))
- Scen.write(bytes([f//256]))
- #
- if Filesize==179109:
- Scen.seek(164208+n*81, 0)
- if Filesize==169822:
- Scen.seek(156265+n*81, 0)
- if Filesize==167559:
- Scen.seek(154002+n*81, 0)
- f = 1000*randrange(0,6)
- Scen.write(bytes([f%256]))
- Scen.write(bytes([f//256]))
- #
- # SET CITY WILL AND ORDER
- #
- if Filesize==179109:
- Scen.seek(164248+n*81, 0)
- if Filesize==169822:
- Scen.seek(156305+n*81, 0)
- if Filesize==167559:
- Scen.seek(154042+n*81, 0)
- f = 5*randrange(12,19)
- Scen.write(bytes([f]))
- f = 5*randrange(12,19)
- Scen.write(bytes([f]))
- #
- # OFFICERS ASSIGNMENT
- #
- for n in e:
- try:
- f = randrange(2,1+round(totaloff/41))
- except:
- f = 2
- while f and len(offi)>fnum:
- q = choice(offi)
- if Filesize==179109:
- Scen.seek(28098+q*152, 0)
- if Filesize==169822:
- Scen.seek(17855+q*152, 0)
- if Filesize==167559:
- Scen.seek(15404+q*152, 0)
- Scen.write(bytes([b]))
- Scen.write(bytes([n]))
- Scen.write(bytes(1))
- Scen.write(bytes([n]))
- Scen.write(bytes(1))
- Scen.write(bytes([3]))
- if Filesize==179109:
- Scen.seek(28107+q*152, 0)
- if Filesize==169822:
- Scen.seek(17864+q*152, 0)
- if Filesize==167559:
- Scen.seek(15413+q*152, 0)
- Scen.write(bytes([randrange(70,100)]))
- offi.remove(q)
- f-=1
- #
- # MAP PREVIEW
- #
- for q in e:
- if Filesize==179109:
- Scen.seek(722+q,0)
- if Filesize==169822:
- Scen.seek(475+q,0)
- if Filesize==167559:
- Scen.seek(418+q,0)
- Scen.write(bytes([c]))
- #
- # FORCE RANK/TITLE
- #
- f = len(e)
- if Filesize==179109:
- Scen.seek(160654+68*c,0)
- if Filesize==169822:
- Scen.seek(152711+68*c,0)
- if Filesize==167559:
- Scen.seek(150260+72*c,0)
- if 1<f<4:
- Scen.write(bytes([8]))
- if 3<f<6:
- Scen.write(bytes([7]))
- if 5<f<8:
- Scen.write(bytes([6]))
- if 7<f<12:
- Scen.write(bytes([5]))
- if 11<f<14:
- Scen.write(bytes([4]))
- if 13<f<18:
- Scen.write(bytes([3]))
- if 17<f<20:
- Scen.write(bytes([2]))
- if 19<f<24:
- Scen.write(bytes([1]))
- #
- # RESEARCHED TECHNIQUES
- #
- if res.get():
- if Filesize==179109:
- Scen.seek(160667+68*c,0)
- if Filesize==169822:
- Scen.seek(152724+68*c,0)
- if Filesize==167559:
- Scen.seek(150273+72*c,0)
- n = 4
- while n:
- if res.get()==1:
- f = choice([0,1,3])*16+choice([0,1,3])
- if res.get()==2:
- f = choice([3,7])*16+choice([3,7])
- if res.get()==3:
- f = choice([7,15])*16+choice([7,15])
- if res.get()==4:
- f = choice([0,1,3,7,15])*16+choice([0,1,3,7,15])
- Scen.write(bytes([f]))
- n-=1
- #
- # RELATIONSHIPS BETWEEN FORCES
- #
- for n in forces:
- if n == c:
- if Filesize==179109:
- Scen.seek(160607+n+n*68,0)
- if Filesize==169822:
- Scen.seek(152664+n+n*68,0)
- if Filesize==167559:
- Scen.seek(150213+n+n*72,0)
- Scen.write(bytes([50]))
- else:
- q = [10*randrange(0,10)]
- if Filesize==179109:
- Scen.seek(160607+n+c*68)
- if Filesize==169822:
- Scen.seek(152664+n+c*68,0)
- if Filesize==167559:
- Scen.seek(150213+n+c*72,0)
- Scen.write(bytes(q))
- if Filesize==179109:
- Scen.seek(160607+c+n*68)
- if Filesize==169822:
- Scen.seek(152664+c+n*68,0)
- if Filesize==167559:
- Scen.seek(150213+c+n*72,0)
- Scen.write(bytes(q))
- #
- # GATES AND PORTS ASSIGNMENT
- #
- for n in e:
- f = gates[n]
- if len(f):
- for t in f:
- if Filesize==179109:
- Scen.seek(167577+t*64, 0)
- if Filesize==169822:
- Scen.seek(159634+t*64, 0)
- if Filesize==167559:
- Scen.seek(157371+t*64, 0)
- Scen.write(bytes([b]))
- r = 100*randrange(5,15)
- Scen.write(bytes([r%256]))
- Scen.write(bytes([r//256]))
- Scen.write(bytes(2))
- r = 100*randrange(5,10)
- Scen.write(bytes([r%256]))
- Scen.write(bytes([r//256]))
- Scen.write(bytes(2))
- r = 1000*randrange(5,10)
- Scen.write(bytes([r%256]))
- Scen.write(bytes([r//256]))
- r = randrange(70,95)
- if Filesize==179109:
- Scen.seek(167638+t*64, 0)
- if Filesize==169822:
- Scen.seek(159695+t*64, 0)
- if Filesize==167559:
- Scen.seek(157432+t*64, 0)
- Scen.write(bytes([r]))
- #
- #NEXT FORCE
- #
- b+=1
- #
- # END OF FORCE CREATION LOOP
- #
- #
- # ADD ALLIANCES WHEN ALL FORCES ARE CREATED
- #
- if AllyVar.get()==1 and len(forces)>2:
- n = randrange(1,len(forces))
- print("There is a total of " + str(len(forces)) + " forces in this Scenario.")
- ally = []
- while n>0:
- roll=1
- while roll:
- f1 = randrange(0,len(forces))
- c1 = forces[f1]
- f2 = randrange(0,len(forces))
- while f2==f1:
- f2 = randrange(0,len(forces))
- c2 = forces[f2]
- allynum = pow(2,c1)+pow(2,c2)
- if allynum in ally:
- roll=1
- if allynum not in ally:
- ally.append(allynum)
- roll=0
- #
- # ALLY SELECTED FORCE 1 TO FORCE 2
- #
- if Filesize==179109:
- Scen.seek(160659+c1*68,0)
- if Filesize==169822:
- Scen.seek(152716+c1*68,0)
- if Filesize==167559:
- Scen.seek(150265+c1*72,0)
- k1 = ord(Scen.read(1))
- k2 = ord(Scen.read(1))
- k3 = ord(Scen.read(1))
- k4 = ord(Scen.read(1))
- k5 = ord(Scen.read(1))
- k6 = ord(Scen.read(1))
- k = 1099511627776*k6 + 4294967296*k5 + 16777216*k4 + 65536*k3 + 256*k2 + k1 + pow(2,c2)
- if Filesize==179109:
- Scen.seek(160659+c1*68,0)
- if Filesize==169822:
- Scen.seek(152716+c1*68,0)
- if Filesize==167559:
- Scen.seek(150265+c1*72,0)
- if k<256:
- dt = [k, 0, 0, 0, 0, 0]
- if 255<k<65536:
- dt = [k%256, k//256, 0, 0, 0, 0]
- if 65535<k<16777216:
- dt = [(k-65536)%256, k%65536//256, k//65536, 0, 0, 0]
- if 16777215<k<4294967296:
- dt = [k%16777216%65536%256, k%16777216%65536//256, k%16777216//65536, k//16777216, 0, 0]
- if 4294967295<k<1099511627776:
- dt = [k%4294967296%16777216%65536%256, k%4294967296%16777216%65536//256, k%4294967296%16777216//65536, k%4294967296//16777216, k//4294967296, 0]
- if k>1099511627775:
- dt = [k%4294967296%16777216%65536%256, k%4294967296%16777216%65536//256, k%4294967296%16777216//65536, k%4294967296//16777216, k//4294967296%256, k//4294967296//256]
- Scen.write(bytes(dt))
- #
- # ALLY FORCE 2 TO FORCE 1
- #
- if Filesize==179109:
- Scen.seek(160659+c2*68,0)
- if Filesize==169822:
- Scen.seek(152716+c2*68,0)
- if Filesize==167559:
- Scen.seek(150265+c2*72,0)
- k1 = ord(Scen.read(1))
- k2 = ord(Scen.read(1))
- k3 = ord(Scen.read(1))
- k4 = ord(Scen.read(1))
- k5 = ord(Scen.read(1))
- k6 = ord(Scen.read(1))
- k = 1099511627776*k6 + 4294967296*k5 + 16777216*k4 + 65536*k3 + 256*k2 + k1 + pow(2,c1)
- if Filesize==179109:
- Scen.seek(160659+c2*68,0)
- if Filesize==169822:
- Scen.seek(152716+c2*68,0)
- if Filesize==167559:
- Scen.seek(150265+c2*72,0)
- if k<256:
- dt = [k, 0, 0, 0, 0, 0]
- if 255<k<65536:
- dt = [k%256, k//256, 0, 0, 0, 0]
- if 65535<k<16777216:
- dt = [(k-65536)%256, k%65536//256, k//65536, 0, 0, 0]
- if 16777215<k<4294967296:
- dt = [k%16777216%65536%256, k%16777216%65536//256, k%16777216//65536, k//16777216, 0, 0]
- if 4294967295<k<1099511627776:
- dt = [k%4294967296%16777216%65536%256, k%4294967296%16777216%65536//256, k%4294967296%16777216//65536, k%4294967296//16777216, k//4294967296, 0]
- if k>1099511627775:
- dt = [k%4294967296%16777216%65536%256, k%4294967296%16777216%65536//256, k%4294967296%16777216//65536, k%4294967296//16777216, k//4294967296%256, k//4294967296//256]
- Scen.write(bytes(dt))
- n-=1
- #
- # ITEM RANDOMIZER
- #
- if ItemVar.get()==1:
- k = 0
- while k<43:
- n = choice([0,0,0,1])
- if n==1:
- owner = choice(leaderslist)
- cty = 255
- if n==0:
- owner = 65535
- cty = randrange(0,42)
- if Filesize==179109:
- Scen.seek(157233+34*k,0)
- if Filesize==169822:
- Scen.seek(147013+57*k, 0)
- if Filesize==167559:
- Scen.seek(144562+57*k, 0)
- Scen.write(bytes([owner%256, owner//256, cty, n]))
- k+=1
- #
- #END OF RANDOMIZER
- #
- print("There is a total of " + str(len(offi)) + " free officers available the first year.")
- print(str(len(ally)) + " alliances have been created.")
- Scen.close()
- messagebox.showinfo("Info", "Scenario has been randomized")
- #
- # WINDOWS GUI CREATION
- #
- window = Tk()
- window.wm_title("RandOTK11 V1.05")
- rdoff = IntVar()
- HistVar = IntVar()
- LifeVar = IntVar()
- CityVar = IntVar()
- CityVar.set(1)
- AllyVar = IntVar()
- AllyVar.set(1)
- ItemVar = IntVar()
- ItemVar.set(0)
- IA = IntVar()
- IA.set(1)
- res = IntVar()
- res.set(0)
- equi = IntVar()
- equi.set(1)
- #
- # GUI : OPEN RANDOMIZE AND EXIT BUTTONS
- #
- openbtn = Button(window, text = "Open File", width = 10, command = openSCEN)
- openbtn.grid(row = 10, column = 1)
- randbtn = Button(window, text = "Randomize", width = 10, state = DISABLED, command = Randomize)
- randbtn.grid(row = 10, column = 2)
- exitbtn = Button(window, text = "Exit", width = 10, command = exitrandotk)
- exitbtn.grid(row = 10, column = 3)
- helpbtn = Button(window, text = "Info", width = 10, command = info)
- helpbtn.grid(row = 10, column = 4)
- #
- # GUI : STARTING DATE - FORCE NUMBER AND FREE CITIES ENTRIES
- #
- SdateLabel = Label(window, text = "Starting Year: ")
- SdateLabel.grid(row = 1, column = 1)
- SdateEntry = Entry(window, width = 8, justify = CENTER)
- SdateEntry.grid(row = 1, column = 2, sticky = W)
- FnumLabel = Label(window, text = "Number of Forces: ")
- FnumLabel.grid(row = 2, column = 1)
- FnumEntry = Entry(window, width = 8, justify = CENTER)
- FnumEntry.grid(row = 2, column = 2, sticky = W)
- FcityLabel = Label(window, text = "Minimum free cities: ")
- FcityLabel.grid(row = 3, column = 1)
- FcityEntry = Entry(window, width = 8, justify = CENTER)
- FcityEntry.insert(0, "0")
- FcityEntry.grid(row = 3, column = 2, sticky = W)
- #
- # GUI : CHECKBOXES
- #
- OffiCkb = Checkbutton(window, text = "Randomize Officers", variable = rdoff)
- OffiCkb.grid(row = 1, column = 4, sticky = W)
- HistCkb = Checkbutton(window, text = "Historical Leaders", variable = HistVar)
- HistCkb.grid(row = 2, column = 4, sticky = W)
- LifeCkb = Checkbutton(window, text = "Randomize Lifespans", variable = LifeVar)
- LifeCkb.grid(row = 3, column = 4, sticky = W)
- CityCkb = Checkbutton(window, text = "Neighbor cities only", variable = CityVar)
- CityCkb.grid(row = 4, column = 4, sticky = W)
- AllyCkb = Checkbutton(window, text = "Add Alliances", variable = AllyVar)
- AllyCkb.grid(row = 5, column = 4, sticky = W)
- ItemCkb = Checkbutton(window, text = "Randomize Items", variable = ItemVar)
- ItemCkb.grid(row = 6, column = 4, sticky = W)
- #
- # GUI : LISTBOX FORCE BALANCE
- #
- BlncLabel = Label(window, text = "Balance Setup:")
- BlncLabel.grid(row = 4, column = 3, sticky = W)
- BlncRdb1 = Radiobutton(window, text = "Similar sized forces", variable = equi, value = 1)
- BlncRdb1.grid(row = 5, column = 3, sticky = W)
- BlncRdb2 = Radiobutton(window, text = "Random sized forces", variable = equi, value = 2)
- BlncRdb2.grid(row = 6, column = 3, sticky = W)
- BlncRdb3 = Radiobutton(window, text = "One city forces", variable = equi, value = 3)
- BlncRdb3.grid(row = 7, column = 3, sticky = W)
- BlncRdb4 = Radiobutton(window, text = "Random Setup", variable = equi, value = 4)
- BlncRdb4.grid(row = 8, column = 3, sticky = W)
- #
- # GUI : LISTBOX TECHNIQUES
- #
- TchqLabel = Label(window, text = "Research Setup:")
- TchqLabel.grid(row = 4, column = 1, sticky = W)
- TchqRdb1 = Radiobutton(window, text = "No research", variable = res, value = 0)
- TchqRdb1.grid(row = 5, column = 1, sticky = W)
- TchqRdb2 = Radiobutton(window, text = "Low research", variable = res, value = 1)
- TchqRdb2.grid(row = 6, column = 1, sticky = W)
- TchqRdb3 = Radiobutton(window, text = "Medium research", variable = res, value = 2)
- TchqRdb3.grid(row = 7, column = 1, sticky = W)
- TchqRdb4 = Radiobutton(window, text = "High research", variable = res, value = 3)
- TchqRdb4.grid(row = 8, column = 1, sticky = W)
- TchqRdb5 = Radiobutton(window, text = "Random research", variable = res, value = 4)
- TchqRdb5.grid(row = 9, column = 1, sticky = W)
- #
- # GUI : RADIOBUTTON IA SETUP
- #
- IALabel = Label(window, text = "IA Setup:")
- IALabel.grid(row = 4, column = 2, sticky = W)
- IARdb1 = Radiobutton(window, text = "Aggressive IA", variable = IA, value = 1)
- IARdb1.grid(row = 5, column = 2, sticky = W)
- IARdb2 = Radiobutton(window, text = "Moderate IA", variable = IA, value = 2)
- IARdb2.grid(row = 6, column = 2, sticky = W)
- IARdb3 = Radiobutton(window, text = "Random IA", variable = IA, value = 3)
- IARdb3.grid(row = 7, column = 2, sticky = W)
- window.mainloop()
- #
- #END OF CODE
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement