Skip to content

Commit

Permalink
Tweak texture gen and note down a bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Sep 26, 2021
1 parent 4c91f5d commit 4008632
Show file tree
Hide file tree
Showing 27 changed files with 112 additions and 49 deletions.
43 changes: 27 additions & 16 deletions luarules/gadgets/map_terrain_generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ local min = math.min
local max = math.max
local random = math.random

local textureCounts = {
veh = 5,
bot = 5,
spider = 5,
uw = 4,
}

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Heightmap manipulation
Expand Down Expand Up @@ -2388,9 +2395,14 @@ local function ReduceMexAllocation(cell, totalMexAlloc, allocFactor)
return totalMexAlloc - allocChange
end

local function AllocateMetalSpots(cells, edges, startCell)
local function AllocateMetalSpots(cells, edges, startCell, params)
GetPathDistances(cells, startCell, "landBotDist", false, true, true)
GetStraightDistances(cells, startCell, "straightDist")

local isTeamGame = Spring.Utilities.Gametype and Spring.Utilities.Gametype.isTeams and Spring.Utilities.Gametype.isTeams()
local isBigTeamGame = Spring.Utilities.Gametype and Spring.Utilities.Gametype.isTeams and Spring.Utilities.Gametype.isBigTeams()
local wantedMexes = params.baseMexesPerSide + floor(random()*4) + ((isTeamGame and 2) or 0) + ((isBigTeamGame and 3) or 0)

local minPathDiff, maxPathDiff
local minDistSum, maxDistSum
local maxCellDist
Expand Down Expand Up @@ -2438,9 +2450,6 @@ local function AllocateMetalSpots(cells, edges, startCell)
maxCellDist = 6000
end

local isTeamGame = Spring.Utilities.Gametype and Spring.Utilities.Gametype.isTeams and Spring.Utilities.Gametype.isTeams()
local isBigTeamGame = Spring.Utilities.Gametype and Spring.Utilities.Gametype.isTeams and Spring.Utilities.Gametype.isBigTeams()

local totalMexAlloc = 0
for i = 1, #cells do
local thisCell = cells[i]
Expand All @@ -2463,6 +2472,7 @@ local function AllocateMetalSpots(cells, edges, startCell)

if thisCell.isMainStartPos then
thisCell.metalSpots = 3
wantedMexes = wantedMexes - thisCell.metalSpots
else
thisCell.mexAlloc = thisCell.startPathFactor*1.2 + thisCell.startDistFactor*1.2 + thisCell.closeDistFactor*0.7 - 0.25
if diffDist and diffDist <= 1 then
Expand All @@ -2488,12 +2498,12 @@ local function AllocateMetalSpots(cells, edges, startCell)

if isTeamGame and thisCell.isAuxStartPos then
thisCell.metalSpots = ((isBigTeamGame and 2) or 1)
wantedMexes = wantedMexes - thisCell.metalSpots
end
end
end

local mexSpots = 6 + floor(random()*6) + ((isTeamGame and 1) or 0) + ((isBigTeamGame and 2) or 0)
while mexSpots > 0 do
while wantedMexes > 0 do
local mexCell = cells[random(1, #cells)]
local randAllocateSum = random()*totalMexAlloc
for i = 1, #cells do
Expand All @@ -2516,21 +2526,20 @@ local function AllocateMetalSpots(cells, edges, startCell)
end

if (mexCell.startPathFactor == 0) and ((not mexCell.mirror) or Dist(mexCell.averageMid, mexCell.mirror.averageMid) > 1200) then
local megaChance = max(0.2, min(0.7, mexCell.mexAlloc*0.7))
if mexCell.mexAlloc and (random() < megaChance) and (not mexCell.unreachable) then
mexCell.megaMex = true
local doubleChance = max(0.2, min(0.7, mexCell.mexAlloc*0.7))
if mexCell.mexAlloc and (random() < doubleChance) and (not mexCell.unreachable) then
mexAssignment = 2
end
end

totalMexAlloc = ReduceMexAllocation(mexCell, totalMexAlloc, 0)
local neighbourFactor = (((mexAssignment == 2) and 0.02) or 0.25)
local neighbourFactor = (((mexAssignment == 2) and 0.05) or 0.4)
for i = 1, #mexCell.neighbours do
totalMexAlloc = ReduceMexAllocation(mexCell.neighbours[i], totalMexAlloc, neighbourFactor)
end
mexCell.metalSpots = (mexCell.metalSpots or 0) + mexAssignment

mexSpots = mexSpots - mexAssignment
wantedMexes = wantedMexes - mexAssignment
end

for i = 1, #cells do
Expand Down Expand Up @@ -2665,7 +2674,7 @@ local function GetTerrainStructure(params)
local startCell = params.StartPositionFunc(cells, edgesSorted, waveFunc, GetWaveHeightMult(tierMin, tierMax, params), params)

tierMin, tierMax = GenerateEdgePassability(params, edgesSorted, tierMin, tierMax)
AllocateMetalSpots(cells, edges, startCell)
AllocateMetalSpots(cells, edges, startCell, params)
SetTreeDensity(cells)

EchoProgress("Terrain structure complete")
Expand Down Expand Up @@ -2716,8 +2725,8 @@ local newParams = {
flatNeighbourIgloo = 560,
lowDiffNeighbourIgloo = 380,
highDiffNeighbourIgloo = 200,
cliffWidth = 20,
rampWidth = 300,
cliffWidth = 22,
rampWidth = 240,
generalWaveMod = 0.9,
waveDirectMult = 0.5,
bucketBase = 55,
Expand All @@ -2727,15 +2736,17 @@ local newParams = {
mapBorderTier = false,
StartPositionFunc = SetStartAndModifyCellTiers_SetPoint,
borderIgloos = true,
forceFord = true,
baseMexesPerSide = 16,
}

local function MakeMap()
local params = newParams
local randomSeed = GetSeed()
--randomSeed = 28950
--randomSeed = 44911 -- A crash
math.randomseed(randomSeed)

Spring.SetGameRulesParam("typemap", "temperate")
Spring.SetGameRulesParam("typemap", "temperate2")
Spring.SetGameRulesParam("mapgen_enabled", 1)

if DISABLE_TERRAIN_GENERATOR then
Expand Down
105 changes: 73 additions & 32 deletions luarules/gadgets/randommapgen_texture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ local UHM_HEIGHT = 64
local UHM_X = UHM_WIDTH/MAP_X
local UHM_Z = UHM_HEIGHT/MAP_Z

local BLOCK_SIZE = 8
local BLOCK_SIZE = 4
local DRAW_OFFSET = 2 * BLOCK_SIZE/MAP_Z - 1

local VEH_NORMAL = 0.892
local BOT_NORMAL = 0.585
local SHALLOW_HEIGHT = -22
local VEH_NORMAL = 0.892
local BOT_NORMAL_PLUS = 0.81
local BOT_NORMAL = 0.585
local SHALLOW_HEIGHT = -22

local USE_SHADING_TEXTURE = (Spring.GetConfigInt("AdvMapShading") == 1)

Expand All @@ -66,6 +67,8 @@ local GL_RGBA = 0x1908
local GL_RGBA16F = 0x881A
local GL_RGBA32F = 0x8814

local COLOR_TEX_LIMIT = 6

local floor = math.floor
local random = math.random

Expand Down Expand Up @@ -195,13 +198,16 @@ local function SetMapTexture(texturePool, mapTexX, mapTexZ, topTexX, topTexZ, to
for i = 1, #texturePool do
local texX = mapTexX[i]
local texZ = mapTexZ[i]
if i == COLOR_TEX_LIMIT then
glColor(1, 1, 1, 1)
end
if texX then
glTexture(texturePool[i].texture)
for j = 1, #texX do
local heightMult = 0.15*(mapHeight[texX[j]][texZ[j]]/400) + 0.85
glColor(1, 1, 1, heightMult)
--glRenderToTexture(topFullTex, DrawTexBlock, texX[j], texZ[j])
--loopCount = RateCheck(loopCount, texturePool[i].texture)
if i < COLOR_TEX_LIMIT then
local prop = math.max(0, math.min(1, (mapHeight[texX[j]][texZ[j]] - 20)/400))
glColor(0.6 + 0.4*(1 - prop), 0.65 + 0.3*prop, 0.9 + 0.1*(1 - prop), 0.95 + 0.1*(1 - prop))
end
glTexRect(texX[j]*MAP_FAC_X - 1, texZ[j]*MAP_FAC_Z - 1,
texX[j]*MAP_FAC_X + DRAW_OFFSET, texZ[j]*MAP_FAC_Z + DRAW_OFFSET)
end
Expand Down Expand Up @@ -422,50 +428,81 @@ local function GetMainTex(height, vehiclePass, botPass, inWater)
end
return 19
end
local heightPower = 1.5^((height - 180)*0.02)
if vehiclePass then
return 1 + floor((random()^heightPower)*5)
return 1 + floor(random()*5)
end
if botPass then
return 6 + floor(random()*5)
end
return random(11, 15)
end

local function GetTopTex(normal, height, vehiclePass, botPass, inWater)
if inWater then
local function GetTopTex(normal, height, vehiclePass, botPassPlus, botPass, inWater)
if inWater and height < SHALLOW_HEIGHT then
if height < SHALLOW_HEIGHT then
return
end
local topTex = GetMainTex(height, vehiclePass, botPass, false)
local topAlpha = 0.7*(1 - (SHALLOW_HEIGHT - height)/SHALLOW_HEIGHT) + 0.28
return topTex, topAlpha
end

if not botPass then
return
local prop = math.max(1, math.min(1, (height - SHALLOW_HEIGHT)/80))
return 16, 0.5 + 0.5*prop
end

local minNorm, maxNorm, topTex
if vehiclePass then
topTex = GetMainTex(height, false, true, underWater)
topTex = GetMainTex(height, false, true)
minNorm, maxNorm = VEH_NORMAL, 1
elseif botPassPlus then
topTex = GetMainTex(height, false, true)
minNorm, maxNorm = BOT_NORMAL_PLUS, VEH_NORMAL
elseif botPass then
topTex = GetMainTex(height, false, false)
minNorm, maxNorm = BOT_NORMAL, BOT_NORMAL_PLUS
else
topTex = GetMainTex(height, false, false, underWater)
minNorm, maxNorm = BOT_NORMAL, VEH_NORMAL
topTex = 16
minNorm, maxNorm = 0, BOT_NORMAL
end

local textureProp = (1 - (normal - minNorm)/(maxNorm - minNorm))
local topAlpha
if vehiclePass then
topAlpha = 0.88*textureProp
topAlpha = 0.95*textureProp
elseif botPassPlus then
topAlpha = textureProp
elseif botPass then
topAlpha = 0.9*textureProp*textureProp
else
topAlpha = 0.15*textureProp
if textureProp > 0.4 then
topAlpha = 0.1
elseif textureProp > 0.2 then
topAlpha = (textureProp - 0.2)*0.5
else
return false
end
end

if textureProp > 0.3 then
if vehiclePass then
if textureProp > 0.2 then
if height%8 > 5 then
local prop = math.max(0, math.min(1, (textureProp - 0.2)/0.3))*0.8 + 0.2
topAlpha = topAlpha - (0.14 + 0.1*prop)
end
end
elseif botPassPlus then
if height%8 > 5 then
topAlpha = 1 - topAlpha
topAlpha = textureProp*0.3 + 0.7
else
topAlpha = textureProp*0.1 + 0.9
end
elseif botPass then
if height%24 > 17 then
topAlpha = (1 - topAlpha)*textureProp + (1 - topAlpha)*textureProp
end
else
local modHeight = height%60
if modHeight > 24 then
local prop = (1 - math.abs(modHeight - 36)/18)*0.05
topAlpha = (1 - topAlpha)*prop + (1 - prop)*topAlpha
else
return false
end
end

Expand All @@ -479,11 +516,14 @@ local function GetSlopeTexture(x, z)
local height = Spring.GetGroundHeight(x, z)
local vehiclePass = (normal > VEH_NORMAL)
local botPass = (normal > BOT_NORMAL)
local inWater = (height < 0 and ((height < SHALLOW_HEIGHT) or (random() < height/SHALLOW_HEIGHT)))
local botPassPlus = (normal > BOT_NORMAL_PLUS)
local inWater = false and (height < 6)

local topTex, topAlpha = GetTopTex(normal, height, vehiclePass, botPass, inWater)
local topTex, topAlpha = GetTopTex(normal, height, vehiclePass, botPassPlus, botPass, inWater)
local mainTex = GetMainTex(height, botPassPlus, botPass, inWater)
local splatTex = GetSplatTex(height, vehiclePass, botPass, inWater)

return GetMainTex(height, vehiclePass, botPass, inWater), GetSplatTex(height, vehiclePass, botPass, inWater), topTex, topAlpha, height
return mainTex, splatTex, topTex, topAlpha, height
end

local function InitializeTextures(useSplat, typemap)
Expand Down Expand Up @@ -533,9 +573,10 @@ end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local function GetTextureSet(textureSetName)
local function SetupTextureSet(textureSetName)
local usetextureSet = textureSetName .. '/'
local texturePath = 'unittextures/tacticalview/' .. usetextureSet

return {
[1] = {
texture = texturePath.."v1.png",
Expand Down Expand Up @@ -643,7 +684,7 @@ end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local texturePool
local vehTexPool, botTexPool, spiderTexPool, uwTexPool
local mapTexX, mapTexZ, topTexX, topTexZ, topTexAlpha, splatTexX, splatTexZ, mapHeight

function gadget:DrawGenesis()
Expand Down Expand Up @@ -671,7 +712,7 @@ local function MakeMapTexture()
mapfullyprocessed = true
return
end
texturePool = GetTextureSet(Spring.GetGameRulesParam("typemap"))
texturePool = SetupTextureSet(Spring.GetGameRulesParam("typemap"))
mapTexX, mapTexZ, topTexX, topTexZ, topTexAlpha, splatTexX, splatTexZ, mapHeight = InitializeTextures(USE_SHADING_TEXTURE, Spring.GetGameRulesParam("typemap"))
initialized = true
end
Expand Down
11 changes: 11 additions & 0 deletions luarules/gadgets/randommapgen_waterparams.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ if gadgetHandler:IsSyncedCode() then
planeColor = { 0.1, 0.1, 0.3},
}
tidal = 18
elseif typemap == "temperate2" then
params = {
absorb = { 0.004, 0.003, 0.002},
baseColor = { 0.4, 0.7, 0.8},
minColor = { 0.1, 0.2, 0.3},
-- surfaceColor = { r, g, b},
-- diffuseColor = { r, g, b},
-- specularColor = { r, g, b},
planeColor = { 0.1, 0.1, 0.3},
}
tidal = 18
elseif typemap == "desert" then
params = {
-- absorb = { 0.004, 0.003, 0.002},
Expand Down
2 changes: 1 addition & 1 deletion mapinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local mapinfo = {
--// dynsun
sunStartAngle = 0.0,
sunOrbitTime = 1440.0,
sunDir = {0.0, 1.0, 2.0, 1e9},
sunDir = {0.25, 1.0, 0.2, 1e9},

--// unit & ground lighting
groundAmbientColor = {0.5, 0.5, 0.5},
Expand Down
Binary file added unittextures/tacticalview/temperate2/b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/b1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/b2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/b3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/b4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/b5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/m.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/n.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/n1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/n2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/n3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/n4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/n5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/uwb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/uwm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/uwn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/uwv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/v.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/v3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/v4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unittextures/tacticalview/temperate2/v5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4008632

Please sign in to comment.