Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from decimal import *
- ################################################################
- #Generate a unique area name based on it's position
- ###############################################################
- DPQ = Decimal(10) ** -3
- def getAreaName(xPos,yPos,zPos):
- return 'SAGrid_('+str(Decimal(xPos).quantize(DPQ))+','+str(Decimal(yPos).quantize(DPQ))+','+str(Decimal(zPos).quantize(DPQ))+')'
- ################################################################
- #Writes pre-entity data to a target file
- ################################################################
- def writePreEntityData(targetFile):
- targetFile.write('<Level>\n')
- targetFile.write(' <MapData FogActive="false" FogColor="1 1 1 1" FogCulling="true" FogEnd="20" FogFalloffExp="1" FogStart="0"'+
- ' GlobalDecalMaxTris="300" Name="" SkyBoxActive="false" SkyBoxColor="1 1 1 1" SkyBoxTexture="">\n')
- targetFile.write(' <MapContents>\n <FileIndex_StaticObjects NumOfFiles="0" />\n')
- targetFile.write(' <FileIndex_Entities NumOfFiles="0" />\n <FileIndex_Decals NumOfFiles="0" />\n')
- targetFile.write(' <StaticObjects />\n <Primitives />\n <Decals />\n <Entities>\n')
- ################################################################
- #Writes post-entity data to a target file
- ################################################################
- def writePostEntityData(targetFile):
- targetFile.write(' </Entities>\n <Misc />\n <StaticObjectCombos />\n')
- targetFile.write(' </MapContents>\n </MapData>\n</Level>\n')
- ################################################################
- #Add a script area to a target file as defined by the properties
- ################################################################
- def addScriptArea(targetFile,areaID,areaName,aScaleX,aScaleY,aScaleZ,aX,aY,aZ,
- playerLookAtCallback='',
- playerLookAtCallbackAutoRemove=False,
- playerInteractCallback='',
- playerInteractCallbackAutoRemove=False,
- itemInteraction=False,
- maxFocusDistance= -1):
- #Write the properties of the area
- targetFile.write(' <Area Active="true" AreaType="Script" Group="0" ID="'+ str(areaID) +
- '" Mesh="" Name="' + str(areaName) +
- '" Rotation="0 0 0" Scale="' + str(Decimal(aScaleX).quantize(DPQ)) + ' ' +
- str(Decimal(aScaleY).quantize(DPQ)) + ' ' +
- str(Decimal(aScaleZ).quantize(DPQ)) +
- '" Tag="" WorldPos="' + str(Decimal(aX).quantize(DPQ)) + ' ' +
- str(Decimal(aY).quantize(DPQ)) + ' ' + str(Decimal(aZ).quantize(DPQ)) + '">\n')
- #Write user variables of the area of the area
- targetFile.write(' <UserVariables>\n')
- targetFile.write(' <Var Name="PlayerLookAtCallback" Value="'+str(playerLookAtCallback)+'" />\n')
- targetFile.write(' <Var Name="PlayerLookAtCallbackAutoRemove" Value="' + str(playerLookAtCallbackAutoRemove) + '" />\n')
- targetFile.write(' <Var Name="PlayerInteractCallback" Value="'+str(playerInteractCallback)+'" />\n')
- targetFile.write(' <Var Name="PlayerInteractCallbackAutoRemove" Value="'+str(playerInteractCallbackAutoRemove)+'" />\n')
- targetFile.write(' <Var Name="ItemInteraction" Value="'+str(itemInteraction)+'" />\n')
- targetFile.write(' <Var Name="MaxFocusDistance" Value="'+str(maxFocusDistance)+'" />\n')
- targetFile.write(' </UserVariables>\n')
- #Close off the area tag
- targetFile.write(' </Area>\n')
- ################################################################
- #Generate a range based on scale factor and from-to variables
- ################################################################
- def dRange(xFrom,xTo,xStep):
- r = Decimal(xFrom)
- to = Decimal(xTo)
- step = Decimal(xStep)
- result = []
- while r < to:
- result.append(r)
- r += step
- return result
- ################################################################
- #Generate Content to an expobj file
- ################################################################
- def writeEntityData(fileName,xRange,yRange,zRange,areaScalex,areaScaley,areaScalez):
- #Write pre-entity stuff to file
- print('Writing to ' + fileName)
- f = open(fileName,'w')
- writePreEntityData(f)
- #Write each area to the expobj file
- totalAreas = 0
- for x in xRange:
- for y in yRange:
- for z in zRange:
- areaName = getAreaName(x,y,z)
- totalAreas += 1
- addScriptArea(f,totalAreas,areaName,areaScalex,areaScaley,areaScalez,x,y,z) #Can add lookat callbacks etc here
- #Write post-entity stuff to file
- writePostEntityData(f)
- f.close()
- print('All done: ' + fileName)
- ################################################################
- #Main Program
- ################################################################
- print 'scale factor (x/z):'
- sfx = Decimal(raw_input())
- print 'scale factor (y):'
- sfy = Decimal(raw_input())
- print 'x-length:'
- xr = dRange(0,Decimal(raw_input()),sfx)
- print 'y-length:'
- yr = dRange(0,Decimal(raw_input()),sfy)
- print 'z-length:'
- zr = dRange(0,Decimal(raw_input()),sfx)
- print 'filename:'
- writeEntityData(raw_input(),xr,yr,zr,sfx,sfy,sfx)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement