Removing Original Sponsors

Rayki

Chieftain
Joined
Nov 19, 2014
Messages
78
Location
Australia
Sorry this one is solved, solution was easy, stick to what I am currently learning.

Through XML I simply applied an update to each faction to make them unplayable by the player and AI.

Here's the code if anyone is interested:
Code:
<GameData>
	<Civilizations>
		<Update>
			<Set Playable="False"/>
			<Where Type="CIVILIZATION_POLYSTRALIA"/>
		</Update>
		<Update>
			<Set AIPlayable="False"/>
			<Where Type="CIVILIZATION_POLYSTRALIA"/>
		</Update>
	</Civilizations>
</GameData>
 
FYI, you can shorten that
Code:
<GameData>
  <Civilizations>
    <Update>
      <Where Type="CIVILIZATION_POLYSTRALIA"/>
      <Set>
        <Playable>False</Playable>
        <AIPlayable>False</AIPlayable>
      </Set>
    </Update>
  </Civilizations>
</GameData>
or
Code:
<GameData>
  <Civilizations>
    <Update>
      <Where Type="CIVILIZATION_POLYSTRALIA"/>
      <Set Playable="False" AIPlayable="False"/>
    </Update>
  </Civilizations>
</GameData>
 
or you can even shorten that with SQL ;]

Code:
UPDATE Civilizations
SET Playable=0, AIPlayable=0
WHERE 
	Type='CIVILIZATION_AFRICAN_UNION' OR 
	Type='CIVILIZATION_ARC' OR 
	Type='CIVILIZATION_BRASILIA' OR
	Type='CIVILIZATION_FRANCO_IBERIA' OR
	Type='CIVILIZATION_KAVITHAN' OR
	Type='CIVILIZATION_PAN_ASIA' OR
	Type='CIVILIZATION_POLYSTRALIA' OR
	Type='CIVILIZATION_RUSSIA'
;

well, it's good to know that there are some alternatives...
 
Code:
UPDATE Civilizations
SET Playable=0, AIPlayable=0
WHERE Type IN ('CIVILIZATION_AFRICAN_UNION', 'CIVILIZATION_ARC',
               'CIVILIZATION_BRASILIA', 'CIVILIZATION_FRANCO_IBERIA',
               'CIVILIZATION_KAVITHAN', 'CIVILIZATION_PAN_ASIA',
               'CIVILIZATION_POLYSTRALIA', 'CIVILIZATION_RUSSIA'
);
 
I was under the impression multiple SET queries didn't work within the same UPDATE (or at least I got an error and someone advised me to separate them out). Neat, will check syntax.

You can NOT do

Code:
<GameData>
  <Civilizations>
    <Update>
      <Where Type="CIVILIZATION_POLYSTRALIA"/>
      <Set Playable="0"/>
      <Set AIPlayable="0"/>
    </Update>
  </Civilizations>
</GameData>

but you can do both the other formats given
 
Wow thanks for all the tips, will help to refine the code and make it easier to find stuff. :)
 
Heh, no matter how you try to optimize your code, whoward always does it better ;]

@whoward
Thx, it's always good to know how to avoid repetitions in a code.
 
Heh, no matter how you try to optimize your code, whoward always does it better ;]

Just gonna leave this here...

Spoiler :
Code:
function GenerateTerrain()
	print("Generating terrain - (Planet Simulator)")
	-- Terrain Type key:
	-- 0.0 == Water/Mountain
	-- 1.0 == Snow
	-- 2.0 == Tundra
	-- 3.0 == Desert
	-- 4.0 == Plains
	-- 5.0 == Grass
	
	--set up a blank floatMap for terrain types
	local terrainMap = FloatMap:New(mapWidth, mapHeight, true, false)
	for i = 0, mapLength, 1 do
		terrainMap.data[i] = 0.0
	end
	
	--### Snow ###--
	--the coldest tiles outside of the tropics become snow regardless of rainfall
	local snowMap = FloatMap:New(mapWidth, mapHeight, true, false)
	for i = 0, mapLength, 1 do
		local y = math_floor(i / mapWidth)
		local zone = terrainMap:GetZone(y)
		local tropics = (zone == mc.NEQUATOR or zone == mc.SEQUATOR)
		local plot = Map_GetPlotByIndex(i)
		if ElevationMap:IsBelowSeaLevel(i) then
			snowMap.data[i] = 0.0 --we'll disregard zeros during threshold determination
		elseif tropics or plot:GetPlotType() == PlotTypes.PLOT_MOUNTAIN then
			snowMap.data[i] = 1.0 --cludge the tropic latitudes to prevent snow here
		else
			snowMap.data[i] = temperatureMap.data[i]
		end
	end
	local snowThreshold = snowMap:FindThresholdFromPercent(mc.snowPercent,false,true)
	--set the coldest tiles to snow in our terrainMap
	for k = 1, #landTab, 1 do
		local i = landTab[k]
		if snowMap.data[i] < snowThreshold then
			terrainMap.data[i] = 1.0
		end
	end
	
	--### Tundra ###--
	--the next coldest tiles become tundra regardless of rainfall
	local tundraMap = FloatMap:New(mapWidth, mapHeight, true, false)
	for i = 0, mapLength, 1 do
		local plot = Map_GetPlotByIndex(i)
		if ElevationMap:IsBelowSeaLevel(i) then
			tundraMap.data[i] = 0.0 --we'll disregard zeros during threshold determination
		elseif terrainMap.data[i] ~= 0.0 or plot:GetPlotType() == PlotTypes.PLOT_MOUNTAIN then
			tundraMap.data[i] = 1.0 --cludge the tiles that have already been assigned on our terrainMap
		else
			tundraMap.data[i] = temperatureMap.data[i]
		end
	end
	local tundraThreshold = tundraMap:FindThresholdFromPercent(mc.tundraPercent,false,true)
	--set the next coldest tiles to tundra in our terrainMap
	for k = 1, #landTab, 1 do
		local i = landTab[k]
		if tundraMap.data[i] < tundraThreshold then
			terrainMap.data[i] = 2.0
		end
	end
	
	--### Desert ###--
	--find the average temperature on the horse latitudes to determine the minimum Desert temperature
	local Ys = {terrainMap:GetYForLatitude(mc.horseLatitudes), terrainMap:GetYForLatitude(-mc.horseLatitudes)}
	local sum = 0
	local count = 0
	for k, y in next, Ys do
		local i = y * mapWidth
		for x = 0, mapRight do
			sum = sum + temperatureMap.data[i + x]
			count = count + 1
		end
	end
	local desertMinTemperature = sum / count
	print(string.format("desertMinTemperature = %.6f", desertMinTemperature))
	--the driest tiles above desertMinTemperature become desert
	local desertMap = FloatMap:New(mapWidth, mapHeight, true, false)
	for i = 0, mapLength, 1 do
		local plot = Map_GetPlotByIndex(i)
		if ElevationMap:IsBelowSeaLevel(i) then
			desertMap.data[i] = 0.0 --we'll disregard zeros during threshold determination
		elseif terrainMap.data[i] ~= 0.0 or temperatureMap.data[i] < desertMinTemperature or plot:GetPlotType() == PlotTypes.PLOT_MOUNTAIN then
			desertMap.data[i] = 1.0 --cludge the tiles that have already been assigned on our terrainMap or are too cold for desert
		else
			desertMap.data[i] = rainfallMap.data[i]
		end
	end
	local desertThreshold = desertMap:FindThresholdFromPercent(mc.desertPercent,false,true)
	--apply the desert tiles to terrainMap
	for k = 1, #landTab, 1 do
		local i = landTab[k]
		if desertMap.data[i] < desertThreshold then
			terrainMap.data[i] = 3.0
		end
	end
	
	--### Plains ###--
	--the driest tiles left after placing desert become plains
	local plainsMap = FloatMap:New(mapWidth, mapHeight, true, false)
	for i = 0, mapLength, 1 do
		local plot = Map_GetPlotByIndex(i)
		if ElevationMap:IsBelowSeaLevel(i) then
			plainsMap.data[i] = 0.0 --we'll disregard zeros during threshold determination
		elseif terrainMap.data[i] ~= 0.0 or plot:GetPlotType() == PlotTypes.PLOT_MOUNTAIN then
			plainsMap.data[i] = 1.0
		else
			plainsMap.data[i] = rainfallMap.data[i]
		end
	end
	local plainsThreshold = plainsMap:FindThresholdFromPercent(mc.plainsPercent,false,true)
	--put plains tiles in our terrainMap
	for k = 1, #landTab, 1 do
		local i = landTab[k]
		if plainsMap.data[i] < plainsThreshold then
			terrainMap.data[i] = 4.0
		end
	end
	
	--### Grass ###--
	--everything left is warm and rainy enough to be grassland
	for k = 1, #landTab, 1 do
		local i = landTab[k]
		local plot = Map_GetPlotByIndex(i)
		if terrainMap.data[i] == 0.0 or plot:GetPlotType() == PlotTypes.PLOT_MOUNTAIN then
			terrainMap.data[i] = 5.0
		end
	end

	-- set our plot types
	for k = 1, #landTab do
		local i = landTab[k]
		local plot = Map_GetPlotByIndex(i)
		if terrainMap.data[i] == 1.0 then
			plot:SetTerrainType(TerrainTypes.TERRAIN_SNOW)
			table.insert(snowTab,i)
		elseif terrainMap.data[i] == 2.0 then
			plot:SetTerrainType(TerrainTypes.TERRAIN_TUNDRA)
		elseif terrainMap.data[i] == 3.0 then
			plot:SetTerrainType(TerrainTypes.TERRAIN_DESERT)
			table.insert(desertTab,i)
		elseif terrainMap.data[i] == 4.0 then
			plot:SetTerrainType(TerrainTypes.TERRAIN_PLAINS)
			table.insert(plainsTab,i)
		elseif terrainMap.data[i] == 5.0 then
			plot:SetTerrainType(TerrainTypes.TERRAIN_GRASS)
			table.insert(grassTab,i)
		end
	end
end

:lol:
 
Back
Top Bottom