Once again, pure world machine + springboard, sources included!
Oh its a 12x12 1v1 map btw.
https://springfiles.springrts.com/?type ... 5eeb2b58a0
Moderator: Moderators
Code: Select all
function gadget:GetInfo()
return {
name = "River Freeze and break",
desc = " freezes all water (teraforms it up) and breaks it on bullet impact",
author = "Picasso",
date = "3rd of May 2010",
license = "GPL3",
layer = 3,
version = 1,
enabled = true
}
end
if (gadgetHandler:IsSyncedCode()) then
local resolutionStep= 10
local iceCrackTresholdDamage = 999
local terrainDamageMap = makeTable(0, Game.mapSizeX/resolutionStep, Game.mapSizeZ/resolutionStep)
local spGetUnitPosition = Spring.GetUnitPosition
-- > Creates a Table and initializes it with default value
function makeTable(default, xDimension, yDimension, zDimension,
boolNegativeMirror)
boolNegativeMirror = boolNegativeMirror or false
xStartIndex = 1
yStartIndex = 1
zStartIndex = 1
if boolNegativeMirror == true then
xStartIndex = -xDimension
yStartIndex = -yDimension
zStartIndex = -zDimension
end
local RetTable = {}
if not xDimension then return default end
for x = xStartIndex, xDimension, 1 do
if yDimension then
RetTable[x] = {}
elseif xDimension then
RetTable[x] = default
else
return default
end
if yDimension then
for y = yStartIndex, yDimension, 1 do
if zDimension then
RetTable[x][y] = {}
else
RetTable[x][y] = default
end
if zDimension then
for z = zStartIndex, zDimension, 1 do
RetTable[x][y][z] = default
end
end
end
end
end
return RetTable
end
function transformToMapCoord(x,z)
return math.ceil(x/resolutionStep), math.ceil(z/resolutionStep)
end
function gadget:GameFrame(frame)
callDistributedTerraformer(frame)
end
function callDistributedTerraformer(frame)
x = (frame % #terrainDamageMap) + 1
for i=1, #terrainDamageMap[frame] do
--we only care about water
if Spring.GetGroundOrigHeight ( x*resolutionStep, z* resolutionStep ) < 0 then
if terrainDamageMap[x][z] > 0 and terrainDamageMap[x] > iceCrackTresholdDamage + math.random(50, 500) and then
--Terraformcode down - the water kills the unit
terrainDamageMap[x][z] = 0
else
--terraform slowly up (freeze)
end
end
end
end
function gadget:Explosion(weaponDefID, x, y, z, AttackerID)
mx,mz = transformToMapCoord(x,z)
terrainDamageMap[mx][mz] =terrainDamageMap[mx][mz] + WeaponDefs[weaponDefID].damage
end
function gadget:UnitDestroyed(unitID, unitDefID, teamID, attackerID)
x,y,z= spGetUnitPosition(unitID)
mx,mz = transformToMapCoord(x,z)
_,maxHp = Spring.GetUnitHealth(unitID)
terrainDamageMap[mx][mz] =terrainDamageMap[mx][mz] + maxHp
end
function gadget:Initialize()
terrainDamageMap = makeTable(0, Game.mapSizeX/resolutionStep, Game.mapSizeZ/resolutionStep)
end
end