Map Scripting spawn problems

drjsta

Chieftain
Joined
Apr 16, 2012
Messages
10
I have been working on a simple map script, but when I try and test it in game, My units are unable to spawn, and just die constantly.
Does anyone know what I am missing? :D

Code:
Spoiler :
Code:
import random

def getDescription():
	return "Jehy's Paradise worlds"

def isAdvancedMap():
	"This map should show up in simple mode"
	return 0

def getWrapX():
	return False
def getWrapY():
	return False
	
def getGridSize()
	grid_sizes = {
		WorldSizeTypes.WORLDSIZE_TINY:     (60,60),
		WorldSizeTypes.WORLDSIZE_SMALL:    (75,75),
		WorldSizeTypes.WORLDSIZE_STANDARD: (90,90),
		WorldSizeTypes.WORLDSIZE_LARGE:    (125,125),
		WorldSizeTypes.WORLDSIZE_HUGE:     (150,150),
		}
		
	if(argsList[0] == -1):
		return []
	[eWorldSize] = argsList
	return grid_sizes[eWorldSize]
	
def generatePlotTypes():
	NiTextOut("Setting Plot Types (Python Paradise) ...")
	gc = CyGlobalContext()
	map = CyMap()
	dice = gc.getGame().getMapRand()
	iFlags = 0
	iW = map.getGridWidth()
	iH = map.getGridHeight()
	plotTypes = [PlotTypes.PLOT_LAND] * (iW*iH)
	
	for x in range(iW):
		for y in range(iH):
			i = y*iW + x
			iN = (y + 1)*iW + x
			iS = (y - 1)*iW + x
			iE = y*iW + (x + 1)
			iW = y*iW + (x - 1)
			iNE = (y + 1)*iW + (x + 1)

			

			rand = random.random()
			if(rand < 0.50 && plotTypes[i] != PlotTypes.PLOT_LAND):
				#Create island
				plotTypes[i] = PlotTypes.PLOT_LAND
				
				for iDirection in range(CardinalDirectionTypes.NUM_CARDINALDIRECTION_TYPES):
					pPlot = plotCardinalDirection(x, y, CardinalDirectionTypes(iDirection))
					plotTypes[pPlot] = PlotTypes.PLOT_LAND
					## Makes a 3 x 3 filled island
					
			if(rand < 0.50) plotTypes[i]
				plotTypes[iN] = PlotTypes.PLOT_OCEAN
			else
				plotTypes[iS] = PlotTypes.PLOT_OCEAN
				#1 Ocean
			if(rand < 0.25)
				plotTypes[iE] = PlotTypes.PLOT_OCEAN
				#2 Ocean
			if(rand < 0.10)
				plotTypes[iNE] = PlotTypes.PLOT_OCEAN
				plotTypes[iE] = PlotTypes.PLOT_OCEAN
				#3 Ocean
			if(rand < 0.05):
				plotTypes[iS] = PlotTypes.PLOT_OCEAN
				plotTypes[iN] = PlotTypes.PLOT_OCEAN
				plotTypes[iE] = PlotTypes.PLOT_OCEAN
				plotTypes[iNE] = PlotTypes.PLOT_OCEAN
				#FoodIsland
				
			if(x == 1) plot.setEurope(EUROPE_WEST)
			if(x == 1) plotTypes[i] = PlotTypes.PLOT_OCEAN
			if(y == 1) plot.setEurope(EUROPE_WEST)
			if(y == 1) plotTypes[i] = PlotTypes.PLOT_OCEAN
return plotTypes		
				
def generateTerrain(self):		
	terrainData = [0]*(self.iWidth*self.iHeight)
	for x in range(self.iWidth):
		for y in range(self.iHeight):
			iI = y*self.iWidth + x
			terrain = self.generateTerrainAtPlot(x, y)
			terrainData[iI] = terrain
		
	#remove marsh next to desert
	for x in range(self.iWidth):
		for y in range(self.iHeight):
			iIndex = y * self.iWidth + x
								
			for iDirection in range(CardinalDirectionTypes.NUM_CARDINALDIRECTION_TYPES):
				pPlot = plotCardinalDirection(x, y, CardinalDirectionTypes(iDirection))
					
				if not pPlot.isNone():
					iOtherIndex = pPlot.getY() * self.iWidth + pPlot.getX()
						
					if ((terrainData[iIndex] == self.terrainDesert) and (terrainData[iOtherIndex] == self.terrainMarsh)) or ((terrainData[iIndex] == self.terrainMarsh) and (terrainData[iOtherIndex] == self.terrainDesert)):
						terrainData[iIndex] = self.terrainPlains
						break
		
return terrainData
 
My units are unable to spawn, and just die constantly.

A couple of questions. :)

1. This is for Colonization (not Civlilization), right ?
(Just want to be sure.)

2. The map itself is created ?

3. Do you know FaireWeather ?
(It is really a fantastic mapscript for colonization. Maybe you could take a look there for comparison.)
 
It is for colonization.
I have been looking at FaireWeather but it's a bit confusing :crazyeye:

What do you mean the map itself is created?

* Also do you know how I could make the entire map visible, like you can in the map editor?
 
So I went in game, and it turns out my map was generated as a huge plain, so there was no ocean
 
Im just going to play around with the map generation idea in some arrays in C++
 
Im just going to play around with the map generation idea in some arrays in C++

This will make your work useless for almost everybody else. :dunno:
(Players and Modders.)

Why don't you try to continue your efforts in the MapScripts (Python) ? :confused:
 
I am much more familiar with compiled languages like C++ C# and the like, so i basically made a map generator in C++ (because it's much easier for me) Now I am trying to convert it over to Python.

So my new code is:
Spoiler :
Code:
from CvPythonExtensions import *
import CvUtil
import CvMapGeneratorUtil 

from array import array
from random import random,randint,seed
import math
import sys
import time
## ---------------Header Files-----------------

def getDescription():
	return "Paradise map script."

def isAdvancedMap():
	"This map should show up in simple mode"
	return 0

def getWrapX():
	return False
def getWrapY():
	return False

def getGridSize(argsList):
	"Reduce grid sizes by one level."
	grid_sizes = {
		WorldSizeTypes.WORLDSIZE_TINY:		(50,50),
		WorldSizeTypes.WORLDSIZE_SMALL:		(75,75),
		WorldSizeTypes.WORLDSIZE_STANDARD:	(90,90),
		WorldSizeTypes.WORLDSIZE_LARGE:		(100,100),
		WorldSizeTypes.WORLDSIZE_HUGE:		(125,125)
		}
	

	if (argsList[0] == -1):
		return []
	[eWorldSize] = argsList
	return grid_sizes[eWorldSize]
	
def generatePlotTypes():
	PRand.seed()
	gc = CyGlobalContext()
	map = CyMap()
	iW = map.GetGridWidth()
	iH = map.GetGridWidth()
	plotTypes = [PlotTypes.PLOT_LAND] * (iW*iH)
	
	plotOcean = gc.getInfoTypeForString("PLOT_OCEAN")
	plotLand = gc.getInfoTypeForString("PLOT_OCEAN")
	plotHill = gc.getInfoTypeForString("PLOT_HILL")
	plotPeak = gc.getInfoTypeForString("PLOT_PEAK")
	
	for x in range(iW):
		for y in range(iH):
			i = y*iW + x
			if x < 3:
				plotTypes[i] = PlotTypes.plotOcean
			if x > iW - 3:
				plotTypes[i] = PlotTypes.plotOcean
			if y < 3:
				plotTypes[i] = PlotTypes.plotOcean
			if y > iH - 3:
				plotTypes[i] = PlotTypes.plotOcean
			else:
				if PRand.random() < 0.03:
					plotTypes[i] = PlotTypes.plotLand
				else:
					plotTypes[i] = PlotTypes.plotOcean
					
	for x in range(iW):
		for y in range(iH):
			i = y*iW + x
            		southPlot = (y + 1) * iW + x
            		northPlot = (y - 1) * iW + x
            		eastPlot  = y * iW + (x + 1)
            		westPlot  = y * iW + (x - 1)
            		soutWPlot = (y + 1) * iW + (x - 1)
            		soutEPlot = (y + 1) * iW + (x + 1)
            		nortWPlot = (y - 1) * iW + (x - 1)
            		nortEPlot = (y - 1) * iW + (x + 1)
			
			if x < 3:
				plotTypes[i] = PlotTypes.plotOcean
			if x > iW - 3:
				plotTypes[i] = PlotTypes.plotOcean
			if y < 3:
				plotTypes[i] = PlotTypes.plotOcean
			if y > iH - 3:
				plotTypes[i] = PlotTypes.plotOcean
			else:
				if plotTypes[i] == plotLand:
					plotTypes[southPlot] = plotTypes.plotHill
                    			plotTypes[northPlot] = plotTypes.plotLand
                    			plotTypes[eastPlot]  = plotTypes.plotLand
                    			plotTypes[westPlot]  = plotTypes.plotLand
                    			plotTypes[nortEPlot] = plotTypes.plotLand
                    			plotTypes[nortWPlot] = plotTypes.plotLand
                    			plotTypes[soutEPlot] = plotTypes.plotHill
                    			plotTypes[soutWPlot] = plotTypes.plotMountain
					
					if PRand.random() < .50: 
						plotTypes[northPlot] = plotTypes.plotOcean
                    			if PRand.random() < .30: 
						plotTypes[nortWPlot] = plotTypes.plotOcean
                    			if PRand.random() < .20: 
						plotTypes[eastPlot]  = plotTypes.plotOcean
                    			if PRand.random() < .10: 
						plotTypes[soutEPlot] = plotTypes.plotOcean
                    			if PRand.random() > .50: 
						plotTypes[southPlot] = plotTypes.plotOcean
                    			if PRand.random() > .70: 
						plotTypes[soutEPlot] = plotTypes.plotOcean
                    			if PRand.random() > .80: 
						plotTypes[westPlot]  = plotTypes.plotOcean
                    			if PRand.random() > .90: 
						plotTypes[nortWPlot] = plotTypes.plotOcean
					
	for x in range(iW):
		for y in range(iH):
			i = y*iW + x
			if x < 3:
				plotTypes[i] = PlotTypes.plotOcean
			if x > iW - 3:
				plotTypes[i] = PlotTypes.plotOcean
			if y < 3:
				plotTypes[i] = PlotTypes.plotOcean
			if y > iH - 3:
				plotTypes[i] = PlotTypes.plotOcean
	return plotTypes

def generateTerrainTypes():
	gc = CyGlobalContext()
    	terrainDesert = gc.getInfoTypeForString("TERRAIN_DESERT")
    	terrainPlains = gc.getInfoTypeForString("TERRAIN_PLAINS")
	terrainIce = gc.getInfoTypeForString("TERRAIN_SNOW")
    	terrainTundra = gc.getInfoTypeForString("TERRAIN_TUNDRA")
    	terrainGrass = gc.getInfoTypeForString("TERRAIN_GRASS")
    	terrainHill = gc.getInfoTypeForString("TERRAIN_HILL")
    	terrainCoast = gc.getInfoTypeForString("TERRAIN_COAST")
    	terrainOcean = gc.getInfoTypeForString("TERRAIN_OCEAN")
    	terrainPeak = gc.getInfoTypeForString("TERRAIN_PEAK")
    	terrainMarsh = gc.getInfoTypeForString("TERRAIN_MARSH")
	plotOcean = gc.getInfoTypeForString("PLOT_OCEAN")
	plotLand = gc.getInfoTypeForString("PLOT_OCEAN")
	plotHill = gc.getInfoTypeForString("PLOT_HILL")
	plotPeak = gc.getInfoTypeForString("PLOT_PEAK")
	
	for y in range (iH):
        	for x in range (iW):
            		i = y * iW + x
            		southPlot = (y + 1) * iW + x
            		northPlot = (y - 1) * iW + x
            		eastPlot = y * iW + (x + 1)
            		westPlot = y * iW + (x - 1)
            		soutWPlot = (y + 1) * iW + (x - 1)
            		soutEPlot = (y + 1) * iW + (x + 1)
            		nortWPlot = (y - 1) * iW + (x - 1)
            		nortEPlot = (y - 1) * iW + (x + 1)

            	else:
                	if plotTypes[i] != plotOcean and plotTypes[i] != terrainTypes.terrainCoast:
                		if plotTypes[southPlot] == plotTypes.plotOcean: 
                    			terrainTypes[southPlot] = terrainTypes.terrainCoast
                		if plotTypes[northPlot] == plotTypes.plotOcean:
                    			terrainTypes[northPlot] = terrainTypes.terrainCoast
                		if plotTypes[eastPlot] == plotTypes.plotOcean:
                    			terrainTypes[eastPlot] = terrainTypes.terrainCoast
                		if plotTypes[westPlot] == plotTypes.plotOcean:
                    			terrainTypes[westPlot] = terrainTypes.terrainCoast
                		if plotTypes[soutEPlot] == plotTypes.plotOcean:
                    			terrainTypes[soutEPlot] = terrainTypes.terrainCoast
                		if plotTypes[nortEPlot] == plotTypes.plotOcean:
                    			terrainTypes[nortEPlot] = terrainTypes.terrainCoast
                		if plotTypes[soutWPlot] == plotTypes.plotOcean:
                    			terrainTypes[soutWPlot] = terrainTypes.terrainCoast
                		if plotTypes[nortWPlot] == plotTypes.plotOcean:
                    			terrainTypes[nortWPlot] = terrainTypes.terrainCoast

                if plotTypes[i] == plotTypes.plotLand:           
			if PRand.random() < .50:
                        	plotTypes[i] = terrainTypes.terrainPlain
                    	elif PRand.random() < .60:
                        	plotTypes[i] = terrainTypes.terrainGrass
                    	elif PRand.random() < .70:
                        	plotTypes[i] = terrainTypes.terrainMarsh
                    	else:
                        	plotTypes[i] = terrainTypes.terrainTundra

                if plotTypes[i] == plotTypes.plotHill:
                    	plotTypes[i] = terrainTypes.terrainDesert
                if plotTypes[i] == plotTypes.plotMountain:
                    	plotTypes[i] = terrainTypesterrainTundra
                            
            	for y in range (iH):
                    	for x in range (iW):
                        	i = y * iW + x
				if x < 3:
					plotTypes[i] = PlotTypes.plotOcean
				if x > iW - 3:
					plotTypes[i] = PlotTypes.plotOcean
				if y < 3:
					plotTypes[i] = PlotTypes.plotOcean
				if y > iH - 3:
					plotTypes[i] = PlotTypes.plotOcean
	return terrainTypes

def addFeature():
	return 0
Dropbox: Click me!
 
Unfortunately I am still having the same problem as before. What happens is a giant plain is generated (like some default generation), and there are no ocean plots, so my ship is killed instantly. I think there is probably some error in my code, but I don't know what it is :wallbash:
 
Tried a whole new script that should make like 20 (1x1) islands in a massive ocean, but nope! Same result [pissed]
 
Hi drjsta,

May be i will write a mistake but something, in your code, shocked me.

In the generateTerrainTypes function you wrote a "else" after a "for".
I never saw that. This is, may be, possible but I don't think it works.
Code:
	....
		[COLOR="Red"]for[/COLOR] x in range (iW):
            		i = y * iW + x
            		southPlot = (y + 1) * iW + x
            		northPlot = (y - 1) * iW + x
            		eastPlot = y * iW + (x + 1)
            		westPlot = y * iW + (x - 1)
            		soutWPlot = (y + 1) * iW + (x - 1)
            		soutEPlot = (y + 1) * iW + (x + 1)
            		nortWPlot = (y - 1) * iW + (x - 1)
            		nortEPlot = (y - 1) * iW + (x + 1)

            	[COLOR="Red"]else[/COLOR]:
			.....
Say me if it's what you want to write. ;)
 
Top Bottom