View Full Version : [Map Script] SpiralGalaxy.py for Final Frontier


cephalo
Feb 12, 2008, 06:58 PM
This map creates a random spiral galaxy for Final Frontier. Most of the resources are toward the center of the galaxy, while most of the habitable planets are toward the ends of the spiral arms.

Download here (http://forums.civfanatics.com/downloads.php?do=file&id=8389)

Put this file in Civilization4\Beyond the Sword\Mods\Final Frontier\PrivateMaps folder. Also, this map requires the default map FinalFrontier.py to be in the same directory, as it uses the starting plot code from that script.

http://forums.civfanatics.com/attachment.php?attachmentid=170612&stc=1&d=1204770704 http://forums.civfanatics.com/attachment.php?attachmentid=170613&stc=1&d=1204770704

Version History:
1.01 - Fixed a multiplayer bug

GeoModder
Feb 13, 2008, 09:39 AM
Looks nice. :cooool:
Do you reckon it will decrease the amount of solar systems? They seem to cluster around the arms (which is normal of course).

cephalo
Feb 13, 2008, 09:53 AM
Looks nice. :cooool:
Do you reckon it will decrease the amount of solar systems? They seem to cluster around the arms (which is normal of course).

There still might be some adjustments needed in regards to the default number of players vs. the map size. I've played through some exploratory phase games, and it seemed ok. In comparison to the default map, this map has alot more unusable map tiles, so it needs to be somewhat bigger.

One concern I still have is the value of starting near the center vs. starting on the outside. I haven't determined how big of an advantage it is to start near the resource rich center. The idea is that the planets will be fewer and farther apart in the middle, but maybe that's not nearly as much of a hindrance as having few resources.

deanej
Feb 13, 2008, 08:29 PM
Is it alright if I include this in my Star Trek mod?

cephalo
Feb 13, 2008, 09:58 PM
Is it alright if I include this in my Star Trek mod?

Absolutely.

Stormwaltz
Feb 15, 2008, 08:20 PM
Outstanding. I've wanted a map like this for a long time, but the thought of making it daunted me.

lobosan
Feb 16, 2008, 02:01 PM
Thank you cephalo! I was looking for a spiral galaxy map but a map script is much better :)

Arctem
Feb 20, 2008, 07:30 PM
Looks sweet. I can't wait to try it. If this is as good as PerfectWorld and Creation, I'll have to go sleepless for a long time.

GeoModder
Feb 21, 2008, 09:52 AM
Cephalo, is it possible to change this to a 'global' maptype?

cephalo
Feb 21, 2008, 09:59 AM
Cephalo, is it possible to change this to a 'global' maptype?

You mean a public map? Right now it does need the starting plot code from FinalFrontier.py, but if you wanted you could probably put both of those files anywhere that you need them. I probably should just copy and paste the needed code right out of FinalFrontier.

GeoModder
Feb 21, 2008, 12:32 PM
No, global like in when going off the map on the westside with a unit you enter on the eastside with it.
I know there's little need with the way the nebula forms on this maptype, but a small passage (or even several passages through the middle of the nebula) would be nice. :please:

cephalo
Feb 21, 2008, 12:58 PM
No, global like in when going off the map on the westside with a unit you enter on the eastside with it.
I know there's little need with the way the nebula forms on this maptype, but a small passage (or even several passages through the middle of the nebula) would be nice. :please:

Hmm, that wouldn't make much sense for a spiral galaxy, but if you want, you can modify the getWrapX and getWrapY functions and set them to return 'True'. That should give you what you are looking for.

jkp1187
Feb 21, 2008, 06:06 PM
This looks great...I may have to fire up Final Frontier again just to try it out.

Zuul
Feb 24, 2008, 09:29 AM
Cool idea :). Maybe add shpere galaxy option? :)

ZB2
Feb 24, 2008, 06:32 PM
Cephalo must have had a vision with the Civilization god to tell him to make this script.

Behold for it is the best. FF mod firing up!

xMikex
Feb 29, 2008, 07:07 PM
very nice.

any chance we might see bar galazies and spherical galaxies?

GoodGame
Mar 20, 2008, 09:56 PM
Just a thought, maybe balance resource density with pirates. Make the rate of pirate appearance directly proportional to resource density. And if possible have the pirates seek to move towards areas rich in resources, and make them less likely to appear on the fringe arms.

T
One concern I still have is the value of starting near the center vs. starting on the outside. I haven't determined how big of an advantage it is to start near the resource rich center. The idea is that the planets will be fewer and farther apart in the middle, but maybe that's not nearly as much of a hindrance as having few resources.

Premier Valle
Mar 22, 2008, 08:01 PM
:trophy2:Great work Cephalo!!!:trophy2:

I just test-played it and is a very good map script!, I'm working in a team making a Babylon 5 mod for FF, and wanted to ask for your permission to distribute your map script with the mod (proper credit given of course).

And I also ask for other galaxy types scripts.

:cheers:

cephalo
Mar 23, 2008, 10:13 AM
:trophy2:Great work Cephalo!!!:trophy2:

I just test-played it and is a very good map script!, I'm working in a team making a Babylon 5 mod for FF, and wanted to ask for your permission to distribute your map script with the mod (proper credit give of course).

And I also ask for other galaxy types scripts.

:cheers:

Go ahead and use it, and thanks for the compliment!

Arexack_heretic
Apr 15, 2008, 11:13 AM
Nice.
I'll play with it some too. :)

PsiCorps
Jun 24, 2008, 06:42 AM
Hi Cephalo, is this script 3.17 compatable

cephalo
Jun 24, 2008, 07:55 AM
Hi Cephalo, is this script 3.17 compatable

The patch happened while my home computer is dismantled, so I haven't tested it. I'm not yet aware of any issue that would prevent it from working unless there are new terrain types or something.

Premier Valle
Jun 26, 2008, 11:27 AM
I'm currently playing with SpiralGalaxy and 3.17, so far everything works fine (I'm in the middle part of the game).

EDIT: I finished the game, and there was no problem at all!.

Phaedris
Mar 03, 2009, 12:24 PM
I really like this map script but I am having problems playing this in multiplayer I keep getting OOS error's whenever I start a game.
I'm using patch 3.17
Does anyone else have problems playing with this in multiplayer?

cephalo
Mar 03, 2009, 01:09 PM
I really like this map script but I am having problems playing this in multiplayer I keep getting OOS error's whenever I start a game.
I'm using patch 3.17
Does anyone else have problems playing with this in multiplayer?

Looks like there's a bug in there. It's supposed to detect a network game and switch to the apporopriate random number generator but it looks like I left it commented out by accident. Funny nobody noticed this for a whole year. :lol:

Ok I fixed it. Download it again and it should work. Let me know because I fixed it without playtesting...:eek:

Phaedris
Mar 03, 2009, 08:50 PM
Seems to work fine now played for a while and no OOS error's :)

Daryl95
Jun 22, 2009, 09:28 AM
Hmm, that wouldn't make much sense for a spiral galaxy, but if you want, you can modify the getWrapX and getWrapY functions and set them to return 'True'. That should give you what you are looking for.

What about a toroidal map?
Is this v3.19 compatible?

cephalo
Jun 22, 2009, 02:45 PM
What about a toroidal map?
Is this v3.19 compatible?

Untested on 3.19. Should work though.

I didn't use a toroidal option because real galaxies are flat discs. If you are at one end of the galaxy, you really do have to cross the whole galaxy to get to the other end. Keep going off the edge and eventually you'll probably hit a whole new galaxy.

PsiCorps
Jun 22, 2009, 04:00 PM
How do you increase the size of the maps without increasing the number of star systems and other features/hazards?

JEELEN
Jun 22, 2009, 05:07 PM
Looks like there's a bug in there. It's supposed to detect a network game and switch to the apporopriate random number generator but it looks like I left it commented out by accident. Funny nobody noticed this for a whole year. :lol:

Ok I fixed it. Download it again and it should work. Let me know because I fixed it without playtesting...:eek:

Odd indeed. I playtested (before the fix) on MOO2Civ with no real OOS problems - as far as I remember. Will use the fixed version for the next patch anyway. (I heard of this mapscript via deanej and was under the impression it was his; credit will be corrected as well.)

Untested on 3.19. Should work though.

Good to know.;)

cephalo
Jun 22, 2009, 06:01 PM
How do you increase the size of the maps without increasing the number of star systems and other features/hazards?

Wow, I haven't looked at this code for a loooong time, but there's gotta be an easy way... I'll try to look into it.

PsiCorps
Jun 23, 2009, 04:02 AM
many thanks, i look forward to your response

Daryl95
Jun 23, 2009, 11:15 AM
Untested on 3.19. Should work though.

I didn't use a toroidal option because real galaxies are flat discs. If you are at one end of the galaxy, you really do have to cross the whole galaxy to get to the other end. Keep going off the edge and eventually you'll probably hit a whole new galaxy.
I understand that but I was just wondering how you make a toroidal mapscript.

Daryl95
Jun 23, 2009, 11:21 AM
I remember editing a couple thing in Final Frontier.py, or was it this one, and then it didn't show up. I was trying to make a mod where planets replaced stars and moons replaced planets. This mod didn't work in the end but why was it that when I removed a few features from the script so it was just a solar system the game didn't show it?

cephalo
Jun 23, 2009, 01:29 PM
I remember editing a couple thing in Final Frontier.py, or was it this one, and then it didn't show up. I was trying to make a mod where planets replaced stars and moons replaced planets. This mod didn't work in the end but why was it that when I removed a few features from the script so it was just a solar system the game didn't show it?

I think all you have to do is change the getWrapX and getWrapY functions and set them to return 'True'.

cephalo
Jun 23, 2009, 01:31 PM
many thanks, i look forward to your response

Ok, I had a look and right at the front of the script there are some tuning variables to adjust the densities of these features.

PsiCorps
Jun 27, 2009, 05:05 AM
Ok, I had a look and right at the front of the script there are some tuning variables to adjust the densities of these features. OK I have tried increasing the map size once before but it didn't work and now i've dived in at the deep end before i learnt to swim. Starting at the beginning, i'll ask questions :lol:
Is there a ratio of height to width that needs to be observed when adjusting the map size?
The variables you mentioned above do you decrease the value to decrease the density of features or increase it to do the same?
Is there a step by step guide to setting up or adjusting the parameters of your map before you even start the game?

cephalo
Jun 27, 2009, 11:09 AM
OK I have tried increasing the map size once before but it didn't work and now i've dived in at the deep end before i learnt to swim. Starting at the beginning, i'll ask questions :lol:
Is there a ratio of height to width that needs to be observed when adjusting the map size?
The variables you mentioned above do you decrease the value to decrease the density of features or increase it to do the same?
Is there a step by step guide to setting up or adjusting the parameters of your map before you even start the game?

I think you can use any size you like, but it's possible that the map requires a square aspect. The feature density is how many of these objects are placed per map square.
So for a standard map with grid size 22x22, you times 4 to get map dimension of 88x88 which is 7744 map tiles. At 0.0045 SolarSystemsPerPlot, that comes to around 34 solar systems.

PsiCorps
Jun 28, 2009, 02:34 AM
Thanks for the info Cephalo, i'll investigate and play around now i have some knowledge.

TC01
Jul 28, 2009, 08:42 AM
I was trying to make it possible for wormholes to be added to this mapscript (like I did with the default FinalFrontier mapscript) and ran into some confusing errors.

Firstly, I wanted to make sure that my wormholes would be placed some distance away from each other and added this function to the mapscript, based on the checkForRoom one that is triggered from each feature generation.

def checkForWormholeRoom(self,x,y,feature):
gc = CyGlobalContext()
mmap = gc.getMap()
xStart = x - (CyMap().getGridWidth() / 4)
xEnd = x + (CyMap().getGridWidth() / 4) + 1
yStart = y - (CyMap().getGridHeight() / 4)
yEnd = y + (CyMap().getGridHeight() / 4) + 1
for yy in range(yStart,yEnd):
for xx in range(xStart,xEnd):
if (yy == yStart or yy == yEnd - 1) and (xx == xStart or xx == xEnd - 1):
continue #skipping corners
i = GetIndex(xx,yy)
if i == -1:
return False
plot = mmap.plot(xx,yy)
if plot.getFeatureType() != feature:
return False
return True

Then, I changed the checkForRoom and shouldAddFeature function line (which requires them to all be true) to this:

if self.shouldPlaceFeature(x,y,self.featureWormhole) and self.checkForRoom(x,y,self.featureWormhole) and self.checkForWormholeRoom(x,y,self.featureWormhole ):

However, when I do this the map seems to hang while "initializing map". So I gave up and removed this... but now my wormholes get dropped within, say, six plots of each other occasionally (which make them useless). Is there something wrong with my code? Or some easier way I can do this?

God-Emperor
Jul 29, 2009, 02:25 PM
I was trying to make it possible for wormholes to be added to this mapscript (like I did with the default FinalFrontier mapscript) and ran into some confusing errors.

Firstly, I wanted to make sure that my wormholes would be placed some distance away from each other and added this function to the mapscript, based on the checkForRoom one that is triggered from each feature generation.

def checkForWormholeRoom(self,x,y,feature):
gc = CyGlobalContext()
mmap = gc.getMap()
xStart = x - (CyMap().getGridWidth() / 4)
xEnd = x + (CyMap().getGridWidth() / 4) + 1
yStart = y - (CyMap().getGridHeight() / 4)
yEnd = y + (CyMap().getGridHeight() / 4) + 1
for yy in range(yStart,yEnd):
for xx in range(xStart,xEnd):
if (yy == yStart or yy == yEnd - 1) and (xx == xStart or xx == xEnd - 1):
continue #skipping corners
i = GetIndex(xx,yy)
if i == -1:
return False
plot = mmap.plot(xx,yy)
if plot.getFeatureType() != feature:
return False
return True

Then, I changed the checkForRoom and shouldAddFeature function line (which requires them to all be true) to this:

if self.shouldPlaceFeature(x,y,self.featureWormhole) and self.checkForRoom(x,y,self.featureWormhole) and self.checkForWormholeRoom(x,y,self.featureWormhole ):

However, when I do this the map seems to hang while "initializing map". So I gave up and removed this... but now my wormholes get dropped within, say, six plots of each other occasionally (which make them useless). Is there something wrong with my code? Or some easier way I can do this?
I think you need to reconsider the meanings of the "if" statements inside your loops.

I haven't looked at the scrip to see what the GetIndex function is doing, but I have to assume it is basically the equivalent of "mmap.plotNum(xx,yy)". If so, then what the "if" statement immediately after it doing is making the function return false if you ware within 25% of the map width or height of an edge.

I assume the function is used to allow the placement of a wormhole. If so, then that first "if" makes it impossible for you to place one within a very wide border around the edge of the map.

The second "if" condition is insisting that every single plot in the very wide area must have the same feature on it. I seriously doubt that you will find any region measuring half the side of the map in both directions where every single plot has the same feature. Thus it will effectively always return false. If the thing calling this loops until it returns true, then this would make it an infinite loop.

My suggestions, based on some assumptions about what you really want:

In the first "if" make it a "continue" instead of a "return False" so that the loops will keep looping, just skipping the rest of the statements in the loop when the plot is off the map (if that's what i = -1 means)

For the second "if" it is less clear what you want. I am guessing that what you really want is to find out if there is already some feature (a wormhole, I expect) in the area. In that case, change the condition from "!=" to "==", so that you will bail out if you find the feature instead of bailing out if you don't find the feature.

TC01
Jul 29, 2009, 08:02 PM
There are actually three if statements there, though.

For the first one (the wide radius around the edge of the map), I'll delete that one. I changed the values of xStart, xEnd, yStart, and yEnd from the original checkForRoom function and didn't look to see where else they were used. So I'll just get rid of this part.

For the second one (what you later say the first one), I'll change it to a continue.

For the third one (the second one, as you say), you are correct in what I want... again, I based it off of the original function, where it is a "!=", but it's a "no feature", rather than a specific feature. I'll change it to a "=="



Just tested it, it worked fine. Thanks God-Emperor!

God-Emperor
Jul 30, 2009, 02:09 AM
There are actually three if statements there, though.

Oops. Bad editing - I left out the line that was supposed to say something like "The first one may be OK but the next two are probably wrong", with my later numbering refering to the two that were wrong. Fortunately you figured out what I meant.

Way back in highschool I had a math teacher who said that when at the blackboard she would write A, say B, think C, but really mean D. I am, fortunately, usually a step or two closer to what I really mean than that.

Just tested it, it worked fine. Thanks God-Emperor!

You're welcome.

Daryl95
Aug 01, 2009, 09:14 AM
How can I add new features to this map and change the features used for spiral arms and the center of the galaxy. I have made new features but when I try to add them to this map it disappears from the map script selection screen. I even tried adding them to the original FinalFrontier.py but then the game crashed. I just copied and pasted code and changed the feature names.

TC01
Aug 02, 2009, 01:37 PM
How can I add new features to this map and change the features used for spiral arms and the center of the galaxy. I have made new features but when I try to add them to this map it disappears from the map script selection screen. I even tried adding them to the original FinalFrontier.py but then the game crashed. I just copied and pasted code and changed the feature names.

I was able to add features (see the discussion above).

In your XML, are the features added to the top or bottom of the file? There are apparently problems if you add to the top. (I used a module so it worked fine).

Daryl95
Aug 02, 2009, 08:03 PM
I was able to add features (see the discussion above).

In your XML, are the features added to the top or bottom of the file? There are apparently problems if you add to the top. (I used a module so it worked fine).
They are at the bottom. I added the Quasar then I loaded the game and it didn't show up. Then I added the Spiral Arm and the mapscript wouldn't show up. It's possible this is from me adding to the FinalFrontier.py but I think it was this one. I know I was having problems with this particular one though.

TC01
Aug 02, 2009, 08:37 PM
They are at the bottom. I added the Quasar then I loaded the game and it didn't show up. Then I added the Spiral Arm and the mapscript wouldn't show up. It's possible this is from me adding to the FinalFrontier.py but I think it was this one. I know I was having problems with this particular one though.

First, do you have python exceptions on?

The process to add a feature to this mapscript is quite complicated. Here's how I did it for WormholesSpiralGalaxy (and for the generic supernova when I did more complicated stuff)

1. Define how many of your feature to be placed per plot. I only wanted two on the entire map, so I don't have a value for this (so it's just the supernova). Put it at the top of the file:

SupernovasPerPlot = 0.00042

2. Add a "ft = featureDef" statement under def initFeatureDefList. These values control, well, I'm not quite sure for some. armDistance controls how far it is from each arm, that I know. You can compare the Solar System and the Black Hole FeatureDefs if you want...

ft = FeatureDef(self.featureWormhole)
ft.arcLength = 0.5
ft.arcLengthRange = 0.7
ft.arcLengthMaxChance = 1.0
ft.armDistance = 0.2
ft.armDistanceRange = 0.3
ft.armDistanceMaxChance = 0.5
self.featureDefList.append(ft)

3. Declare your feature in the beginning of def generateFeatures.

self.featureWormhole = gc.getInfoTypeForString("FEATURE_WORMHOLE")

4. Define how many times you want your feature to appear on the map. For WormholesSpiralGalaxy, I only wanted two, so this is the Supernova line:

numSupernovas = int(float(numPlots) * SupernovasPerPlot)

5. Again, this is the supernova, since I did different stuff. But this is the actual code to find the plot the feature should be placed. Same function as the two above.

#Supernovas
numPlaced = 0
iterations = 0
while(True):
iterations += 1
if iterations > 20:
print "Not all supernovas could be placed!!!!!!!!!!!!!!"
break
if numPlaced == numSupernovas:
break
for n in range(len(plotList)):
x,y = plotList[n]
if self.shouldPlaceFeature(x,y,self.featureSupernova) and self.checkForRoom(x,y,self.featureSupernova):
numPlaced += 1
self.placeSupernova(x,y)
if numPlaced == numSupernovas:
break
print "Placed %(p)d out of %(n)d supernovas" % {"p":numPlaced,"n":numSupernovas}

6. Then, there's the function to actually place the feature (called from the function above. It should be idented under the def generateFeatures function. The "placeholder" is whatever feature you want to surround the feature. Here is the wormhole one again:

def placeWormhole(self, x, y):
gc = CyGlobalContext()
mmap = gc.getMap()
xStart = x - 2
xEnd = x + 3
yStart = y - 2
yEnd = y + 3
for yy in range(yStart,yEnd):
for xx in range(xStart,xEnd):
if (yy == yStart or yy == yEnd - 1) and (xx == xStart or xx == xEnd - 1):
continue #skipping corners
plot = mmap.plot(xx,yy)
if x == xx and y == yy:
plot.setFeatureType(self.featureWormhole,0)
else:
plot.setFeatureType(self.featurePlaceHolder,0)

Challs
Apr 24, 2010, 12:44 PM
Looks nice in the picture. I just hope i does the same in game :)

God-Emperor
Apr 24, 2010, 04:40 PM
It works well.

They are a bit larger (in total number of plots) than the regular Final Frontier map of the same size category but there are typically more unusable plots so it works out to a similar number of star systems (it might be slightly more). Exploration is a little harder and maintenance is a little higher due to things being a little more spread out.