Advertisement
Civilization Fanatics' Center

Go Back   Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Colonization > Civ4Col - Creation & Customization

Notices

Civ4Col - Creation & Customization Forum for Civ4 Colonization modding and customization discussions.

Reply
 
Thread Tools
Old Apr 16, 2012, 03:27 AM   #1
drjsta
Chieftain
 
Join Date: Apr 2012
Posts: 10
Map Scripting spawn problems

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?

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
drjsta is offline   Reply With Quote
Old Apr 16, 2012, 03:40 AM   #2
raystuttgart
Civ4Col Modder
 
raystuttgart's Avatar
 
Join Date: Jan 2011
Location: Stuttgart, Germany
Posts: 4,190
Quote:
Originally Posted by drjsta View Post
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.)
__________________
Religion and Revolution
(Retired Modder)
raystuttgart is offline   Reply With Quote
Old Apr 16, 2012, 03:56 PM   #3
drjsta
Chieftain
 
Join Date: Apr 2012
Posts: 10
It is for colonization.
I have been looking at FaireWeather but it's a bit confusing

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?

Last edited by drjsta; Apr 16, 2012 at 04:29 PM. Reason: Another question
drjsta is offline   Reply With Quote
Old Apr 16, 2012, 05:35 PM   #4
drjsta
Chieftain
 
Join Date: Apr 2012
Posts: 10
So I went in game, and it turns out my map was generated as a huge plain, so there was no ocean
drjsta is offline   Reply With Quote
Old Apr 16, 2012, 09:05 PM   #5
drjsta
Chieftain
 
Join Date: Apr 2012
Posts: 10
Im just going to play around with the map generation idea in some arrays in C++
drjsta is offline   Reply With Quote
Old Apr 17, 2012, 02:34 AM   #6
raystuttgart
Civ4Col Modder
 
raystuttgart's Avatar
 
Join Date: Jan 2011
Location: Stuttgart, Germany
Posts: 4,190
Quote:
Originally Posted by drjsta View Post
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.
(Players and Modders.)

Why don't you try to continue your efforts in the MapScripts (Python) ?
__________________
Religion and Revolution
(Retired Modder)
raystuttgart is offline   Reply With Quote
Old Apr 17, 2012, 04:30 PM   #7
drjsta
Chieftain
 
Join Date: Apr 2012
Posts: 10
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!

Last edited by drjsta; Apr 17, 2012 at 04:39 PM. Reason: Added dropbox link
drjsta is offline   Reply With Quote
Old Apr 17, 2012, 04:33 PM   #8
drjsta
Chieftain
 
Join Date: Apr 2012
Posts: 10
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
drjsta is offline   Reply With Quote
Old Apr 17, 2012, 10:08 PM   #9
drjsta
Chieftain
 
Join Date: Apr 2012
Posts: 10
Tried a whole new script that should make like 20 (1x1) islands in a massive ocean, but nope! Same result
drjsta is offline   Reply With Quote
Old Apr 24, 2012, 04:45 PM   #10
M07
Prince
 
M07's Avatar
 
Join Date: Mar 2009
Location: France
Posts: 329
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:
	....
		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:
			.....
Say me if it's what you want to write.
__________________
Save the bamboos! Eat a panda!

Mod of CivilizationIV Colonization

[MOD] Dawn of a New Era v4.00

Last edited by M07; Apr 24, 2012 at 04:48 PM.
M07 is offline   Reply With Quote
Reply

Bookmarks

Tags
map script

Go Back Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Colonization > Civ4Col - Creation & Customization > Map Scripting spawn problems

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Advertisement

All times are GMT -6. The time now is 10:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
This site is copyright Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR