God-Emperor
Deity
I think you need to reconsider the meanings of the "if" statements inside your loops.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.
Code: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:
Code: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 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.